#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.
This commit is contained in:
R David Murray 2014-03-23 15:08:43 -04:00
parent 91e7f04fc5
commit e1b6f97dae
5 changed files with 23 additions and 1 deletions

View file

@ -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')