if it represented midnight in UTC. This behavior was considered obscure and
error-prone and has been removed in Python 3.5. See :issue:`13936` for full
details.
+
+* :meth:`unittest.TestCase.assertRaisesRegex` and
+ :meth:`~unittest.TestCase.assertWarnsRegex` now raise a :exc:`TypeError` if
+ the second argument is not a string or a compiled :mod:`regex`. You may have
+ tests with an invalid second argument that have until 3.5 been falsely
+ passing which will now raise TypeErrors (:issue:`20145`).
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
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')
Albert Hofkamp
Tomas Hoger
Jonathan Hogg
+Kamilla Holanda
Steve Holden
Akintayo Holder
Thomas Holenstein
Library
-------
+- Issue #20145: `assertRaisesRegex` and `assertWarnsRegex` now raise a
+ TypeError if the second argument is not a string or compiled regex.
+
- Issue #20633: Replace relative import by absolute import.
- Issue #20980: Stop wrapping exception when using ThreadPool.