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.
This commit is contained in:
R David Murray 2014-03-25 15:31:50 -04:00
parent 87d13ea56d
commit ef1c26798c
4 changed files with 17 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