diff options
author | R David Murray <rdmurray@bitdance.com> | 2014-03-25 15:31:50 -0400 |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2014-03-25 15:31:50 -0400 |
commit | ef1c26798ca95d10d29979c6fef77ac3b6f27c26 (patch) | |
tree | 074534905e338281d8f9937635becd0cd27bc86e /Lib/unittest/test/test_case.py | |
parent | 87d13ea56d58851c35952aa8dac24168fceac15a (diff) | |
download | cpython-git-ef1c26798ca95d10d29979c6fef77ac3b6f27c26.tar.gz |
backport: #20145: assert[Raises|Warns]Regex now raise TypeError on bad regex.
Previously a non-string, non-regex second argument and missing callable
argument could cause the test to appear to always pass.
Initial patch by Kamilla Holanda.
Diffstat (limited to 'Lib/unittest/test/test_case.py')
-rw-r--r-- | Lib/unittest/test/test_case.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index 363390af09..49325784d2 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -1126,6 +1126,18 @@ test case self.assertRaisesRegex, Exception, 'x', lambda: None) + def testAssertRaisesRegexInvalidRegex(self): + # Issue 20145. + class MyExc(Exception): + pass + self.assertRaises(TypeError, self.assertRaisesRegex, MyExc, lambda: True) + + def testAssertWarnsRegexInvalidRegex(self): + # Issue 20145. + class MyWarn(Warning): + pass + self.assertRaises(TypeError, self.assertWarnsRegex, MyWarn, lambda: True) + def testAssertRaisesRegexMismatch(self): def Stub(): raise Exception('Unexpected') |