PyDocs

Nav

Development Tools

TestCase.assertWarnsRegex

unittest

method of TestCase · Added in 3.2 (source)
  • TestCase.assertWarnsRegex(warning, regex, callable, *args, **kwds)
  • TestCase.assertWarnsRegex(warning, regex, *, msg=None)
Asserts that the message in a triggered warning matches a regexp.
Basic functioning is similar to assertWarns() with the addition
that only warnings whose messages also match the regular expression
are considered successful matches.

Args:
    expected_warning: Warning class expected to be triggered.
    expected_regex: Regex (re.Pattern object or string) expected
            to be found in error message.
    args: Function to be called and extra positional args.
    kwargs: Extra kwargs.
    msg: Optional message used in case of failure. Can only be used
            when assertWarnsRegex is used as a context manager.
Changed in 3.3, 3.15
  • 3.3: Added the msg keyword argument when used as a context manager.
  • 3.15: Warnings that do not match the specified category or regex are no longer swallowed. Nested context managers are now supported.
0 Examples
No examples for unittest/TestCase.assertWarnsRegex.
See Also
No see-alsos for unittest/TestCase.assertWarnsRegex
0 Notes
No notes for TestCase.assertWarnsRegex