mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
#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:
parent
91e7f04fc5
commit
e1b6f97dae
5 changed files with 23 additions and 1 deletions
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue