MCPcopy Index your code
hub / github.com/python/cpython / assertWarnsRegex

Method assertWarnsRegex

Lib/unittest/case.py:1416–1433  ·  view source on GitHub ↗

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

(self, expected_warning, expected_regex,
                         *args, **kwargs)

Source from the content-addressed store, hash-verified

1414 return context.handle('assertRaisesRegex', args, kwargs)
1415
1416 def assertWarnsRegex(self, expected_warning, expected_regex,
1417 *args, **kwargs):
1418 """Asserts that the message in a triggered warning matches a regexp.
1419 Basic functioning is similar to assertWarns() with the addition
1420 that only warnings whose messages also match the regular expression
1421 are considered successful matches.
1422
1423 Args:
1424 expected_warning: Warning class expected to be triggered.
1425 expected_regex: Regex (re.Pattern object or string) expected
1426 to be found in error message.
1427 args: Function to be called and extra positional args.
1428 kwargs: Extra kwargs.
1429 msg: Optional message used in case of failure. Can only be used
1430 when assertWarnsRegex is used as a context manager.
1431 """
1432 context = _AssertWarnsContext(expected_warning, self, expected_regex)
1433 return context.handle('assertWarnsRegex', args, kwargs)
1434
1435 def assertRegex(self, text, expected_regex, msg=None):
1436 """Fail the test unless the text matches the regular expression."""

Callers 15

test_warningsMethod · 0.80
test_decode_warningsMethod · 0.80
genMethod · 0.80
test_asendMethod · 0.80
test_athrowMethod · 0.80
test_acloseMethod · 0.80

Calls 2

_AssertWarnsContextClass · 0.85
handleMethod · 0.45

Tested by 15

test_warningsMethod · 0.64
test_decode_warningsMethod · 0.64
genMethod · 0.64
test_asendMethod · 0.64
test_athrowMethod · 0.64
test_acloseMethod · 0.64