summaryrefslogtreecommitdiffstats
path: root/Lib/test/support
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-06-17 16:07:13 (GMT)
committerGitHub <noreply@github.com>2020-06-17 16:07:13 (GMT)
commit8362893e3fe083df2ec8bb94c28b1a78383eadbf (patch)
treec485a614b45419ebbd2b648de6e8e2efa2279515 /Lib/test/support
parent8e34e92caa73259620dd242b92d26edd0949b4ba (diff)
downloadcpython-8362893e3fe083df2ec8bb94c28b1a78383eadbf.zip
cpython-8362893e3fe083df2ec8bb94c28b1a78383eadbf.tar.gz
cpython-8362893e3fe083df2ec8bb94c28b1a78383eadbf.tar.bz2
bpo-41003: Fix test_copyreg when numpy is installed (GH-20935)
Fix test_copyreg when numpy is installed: test.pickletester now saves/restores warnings.filters when importing numpy, to ignore filters installed by numpy. Add the save_restore_warnings_filters() function to the test.support.warnings_helper module.
Diffstat (limited to 'Lib/test/support')
-rw-r--r--Lib/test/support/warnings_helper.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/support/warnings_helper.py b/Lib/test/support/warnings_helper.py
index c9f9045..de23e6b 100644
--- a/Lib/test/support/warnings_helper.py
+++ b/Lib/test/support/warnings_helper.py
@@ -178,3 +178,12 @@ def _filterwarnings(filters, quiet=False):
if missing:
raise AssertionError("filter (%r, %s) did not catch any warning" %
missing[0])
+
+
+@contextlib.contextmanager
+def save_restore_warnings_filters():
+ old_filters = warnings.filters[:]
+ try:
+ yield
+ finally:
+ warnings.filters[:] = old_filters