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 | 8623486761fd2de4608c668341f2efc0db2e284e (patch) | |
tree | 117cd288f79a95b1e07c8fbc70f0af7ffb651095 /tests/test_testing.py | |
parent | 01e12e85608494ec51f5095f56c78dadb28a916b (diff) | |
download | python-coveragepy-8623486761fd2de4608c668341f2efc0db2e284e.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 d86207e..05bf0c9 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!"]): |