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.
This commit is contained in:
Victor Stinner 2020-06-17 18:07:13 +02:00 committed by GitHub
parent 8e34e92caa
commit 8362893e3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 12 deletions

View file

@ -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