@@ -1279,8 +1279,10 @@ def assertRegex(self, text, expected_regex, msg=None):
12791279 assert expected_regex , "expected_regex must not be empty."
12801280 expected_regex = re .compile (expected_regex )
12811281 if not expected_regex .search (text ):
1282- msg = msg or "Regex didn't match"
1283- msg = '%s: %r not found in %r' % (msg , expected_regex .pattern , text )
1282+ standardMsg = "Regex didn't match: %r not found in %r" % (
1283+ expected_regex .pattern , text )
1284+ # _formatMessage ensures the longMessage option is respected
1285+ msg = self ._formatMessage (msg , standardMsg )
12841286 raise self .failureException (msg )
12851287
12861288 def assertNotRegex (self , text , unexpected_regex , msg = None ):
@@ -1289,11 +1291,12 @@ def assertNotRegex(self, text, unexpected_regex, msg=None):
12891291 unexpected_regex = re .compile (unexpected_regex )
12901292 match = unexpected_regex .search (text )
12911293 if match :
1292- msg = msg or "Regex matched"
1293- msg = '%s: %r matches %r in %r' % (msg ,
1294- text [match .start ():match .end ()],
1295- unexpected_regex .pattern ,
1296- text )
1294+ standardMsg = 'Regex matched: %r matches %r in %r' % (
1295+ text [match .start () : match .end ()],
1296+ unexpected_regex .pattern ,
1297+ text )
1298+ # _formatMessage ensures the longMessage option is respected
1299+ msg = self ._formatMessage (msg , standardMsg )
12971300 raise self .failureException (msg )
12981301
12991302
@@ -1315,6 +1318,7 @@ def deprecated_func(*args, **kwargs):
13151318 failIf = _deprecate (assertFalse )
13161319 assertRaisesRegexp = _deprecate (assertRaisesRegex )
13171320 assertRegexpMatches = _deprecate (assertRegex )
1321+ assertNotRegexpMatches = _deprecate (assertNotRegex )
13181322
13191323
13201324
0 commit comments