diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-12-09 12:24:12 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-02-04 06:38:50 -0500 |
commit | 340c56ba503f0000bf684110c2a8c8ade9d5d60b (patch) | |
tree | 9713c428526e29df9a113ae20a41ed5e9c98ff12 /tests/helpers.py | |
parent | cf712c665dffcd2e1e939b9eb079974449437828 (diff) | |
download | python-coveragepy-git-340c56ba503f0000bf684110c2a8c8ade9d5d60b.tar.gz |
refactor(test): a context manager to swallow warnings
Diffstat (limited to 'tests/helpers.py')
-rw-r--r-- | tests/helpers.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py index 29464d1c..890bd7c5 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -12,6 +12,7 @@ import re import shutil import subprocess import textwrap +import warnings from unittest import mock @@ -308,3 +309,14 @@ def assert_coverage_warnings(warns, *msgs): assert expected.search(actual), f"{actual!r} didn't match {expected!r}" else: assert expected == actual + + +@contextlib.contextmanager +def swallow_warnings(message=r".", category=CoverageWarning): + """Swallow particular warnings. + + It's OK if they happen, or if they don't happen. Just ignore them. + """ + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=category, message=message) + yield |