unittest.TestCase.assertWarnsRegex()

assertWarnsRegex(warning, regex, callable, *args, **kwds) assertWarnsRegex(warning, regex, msg=None)

Like assertWarns() but also tests that regex matches on the message of the triggered warning. regex may be a regular expression object or a string containing a regular expression suitable for use by re.search(). Example:

self.assertWarnsRegex(DeprecationWarning,
                      r'legacy_function\(\) is deprecated',
                      legacy_function, 'XYZ')

or:

with self.assertWarnsRegex(RuntimeWarning, 'unsafe frobnicating'):
    frobnicate('/etc/passwd')

New in version 3.2.

Changed in version 3.3: Added the msg keyword argument when used as a context manager.

doc_python
2016-10-07 17:46:25
Comments
Leave a Comment

Please login to continue.