From e1b6f97daedcfab29c1139ddb8c41292cd7de472 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Sun, 23 Mar 2014 15:08:43 -0400 Subject: #20145: assert[Raises|Warns]Regex now raise TypeError on bad regex. Previously a non-string, non-regex second argument could cause the test to always pass. Initial patch by Kamilla Holanda. --- Lib/unittest/test/test_case.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Lib/unittest/test/test_case.py') 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') -- cgit v1.2.1