summaryrefslogtreecommitdiff
path: root/Lib/unittest/test/test_case.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2014-03-25 15:31:50 -0400
committerR David Murray <rdmurray@bitdance.com>2014-03-25 15:31:50 -0400
commitef1c26798ca95d10d29979c6fef77ac3b6f27c26 (patch)
tree074534905e338281d8f9937635becd0cd27bc86e /Lib/unittest/test/test_case.py
parent87d13ea56d58851c35952aa8dac24168fceac15a (diff)
downloadcpython-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.py12
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')