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)
| 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.""" |