#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

@ -143,7 +143,7 @@ class _AssertRaisesBaseContext(_BaseTestCaseContext):
self.obj_name = str(callable_obj)
else:
self.obj_name = None
if isinstance(expected_regex, (bytes, str)):
if expected_regex is not None:
expected_regex = re.compile(expected_regex)
self.expected_regex = expected_regex
self.msg = None