summaryrefslogtreecommitdiff
path: root/tests/helpers.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-12-09 12:24:12 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-12-12 15:36:37 -0500
commitb8a2153e8711d0275f71e9e66e566d49750e8360 (patch)
tree917f481f91866864156cd3cb53d1c03e7e8706cb /tests/helpers.py
parent03d9059877ffe148966e2c0022b3275eb6c02cfd (diff)
downloadpython-coveragepy-git-nedbat/pytest-7.tar.gz
refactor(test): a context manager to swallow warningsnedbat/pytest-7
Diffstat (limited to 'tests/helpers.py')
-rw-r--r--tests/helpers.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py
index 82d8b18f..c928c01e 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
@@ -301,3 +302,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