return True
expected_regexp = self.expected_regexp
- if isinstance(expected_regexp, basestring):
- expected_regexp = re.compile(expected_regexp)
if not expected_regexp.search(str(exc_value)):
raise self.failureException('"%s" does not match "%s"' %
(expected_regexp.pattern, str(exc_value)))
args: Extra args.
kwargs: Extra kwargs.
"""
+ if expected_regexp is not None:
+ expected_regexp = re.compile(expected_regexp)
context = _AssertRaisesContext(expected_exception, self, expected_regexp)
if callable_obj is None:
return context
self.assertRaisesRegexp, Exception, u'x',
lambda: None)
+ def testAssertRaisesRegexpInvalidRegexp(self):
+ # Issue 20145.
+ class MyExc(Exception):
+ pass
+ self.assertRaises(TypeError, self.assertRaisesRegexp, MyExc, lambda: True)
+
def testAssertRaisesRegexpMismatch(self):
def Stub():
raise Exception('Unexpected')
Albert Hofkamp
Tomas Hoger
Jonathan Hogg
+Kamilla Holanda
Steve Holden
Akintayo Holder
Thomas Holenstein
Library
-------
+- Issue #20145: `assertRaisesRegex` now raises a TypeError if the second
+ argument is not a string or compiled regex.
+
- Issue #21058: Fix a leak of file descriptor in tempfile.NamedTemporaryFile(),
close the file descriptor if os.fdopen() fails