diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-05-30 17:39:20 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-05-30 18:03:05 -0400 |
commit | 30c023b5b74f9c798645cbb3f35362ae046a4c25 (patch) | |
tree | e86df1a4c044ec9b2919068297dfd91a382eeb84 /tests/helpers.py | |
parent | 22fe2eb167a18dda8fd3e14cbf9166a1c7331fb9 (diff) | |
download | python-coveragepy-git-30c023b5b74f9c798645cbb3f35362ae046a4c25.tar.gz |
feat: warnings are now real warnings
This makes coverage warnings visible when running test suites under
pytest. But it also means some uninteresting warnings would show up in
our own test suite, so we had to catch or suppress those.
Diffstat (limited to 'tests/helpers.py')
-rw-r--r-- | tests/helpers.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py index 21459cd4..369875b9 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -14,6 +14,7 @@ import textwrap from unittest import mock +from coverage.exceptions import CoverageWarning from coverage.misc import output_encoding @@ -262,3 +263,17 @@ def assert_count_equal(a, b): This only works for hashable elements. """ assert collections.Counter(list(a)) == collections.Counter(list(b)) + + +def assert_coverage_warnings(warns, *msgs): + """ + Assert that `warns` are all CoverageWarning's, and have `msgs` as messages. + """ + assert msgs # don't call this without some messages. + assert len(warns) == len(msgs) + assert all(w.category == CoverageWarning for w in warns) + for actual, expected in zip((w.message.args[0] for w in warns), msgs): + if hasattr(expected, "search"): + assert expected.search(actual), f"{actual!r} didn't match {expected!r}" + else: + assert expected == actual |