diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2017-04-06 19:05:13 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2017-04-06 19:05:13 -0400 |
commit | 2d03d1b61673489e89b77789d864626c24791ced (patch) | |
tree | 662be2896a0b95b67c42ca5b0734866c4e868aee /tests/test_testing.py | |
parent | dce26d45a70e45972ac44b7aa23a68f9bb3ae749 (diff) | |
download | python-coveragepy-git-2d03d1b61673489e89b77789d864626c24791ced.tar.gz |
Beef up the assert_warnings test helper
Diffstat (limited to 'tests/test_testing.py')
-rw-r--r-- | tests/test_testing.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/test_testing.py b/tests/test_testing.py index d86207ed..05bf0c92 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -114,6 +114,17 @@ class CoverageTestTest(CoverageTest): with self.assert_warnings(cov, ["Not me"]): cov._warn("Hello there!") + # Try checking a warning that shouldn't appear: happy case. + with self.assert_warnings(cov, ["Hi"], not_warnings=["Bye"]): + cov._warn("Hi") + + # But it should fail if the unexpected warning does appear. + warn_regex = r"Found warning 'Bye' in \['Hi', 'Bye'\]" + with self.assertRaisesRegex(AssertionError, warn_regex): + with self.assert_warnings(cov, ["Hi"], not_warnings=["Bye"]): + cov._warn("Hi") + cov._warn("Bye") + # assert_warnings shouldn't hide a real exception. with self.assertRaises(ZeroDivisionError): with self.assert_warnings(cov, ["Hello there!"]): |