import os
import sys
import unittest
-import warnings
from test.support import run_unittest
+from test.support.warnings_helper import save_restore_warnings_filters
here = os.path.dirname(__file__) or os.curdir
def test_suite():
- old_filters = warnings.filters[:]
suite = unittest.TestSuite()
for fn in os.listdir(here):
if fn.startswith("test") and fn.endswith(".py"):
modname = "distutils.tests." + fn[:-3]
- __import__(modname)
+ # bpo-40055: Save/restore warnings filters to leave them unchanged.
+ # Importing tests imports docutils which imports pkg_resources
+ # which adds a warnings filter.
+ with save_restore_warnings_filters():
+ __import__(modname)
module = sys.modules[modname]
suite.addTest(module.test_suite())
- # bpo-40055: Save/restore warnings filters to leave them unchanged.
- # Importing tests imports docutils which imports pkg_resources which adds a
- # warnings filter.
- warnings.filters[:] = old_filters
return suite
except ImportError:
_testbuffer = None
-try:
- import numpy as np
-except ImportError:
- np = None
-
from test import support
from test.support import (
TestFailed, TESTFN, run_with_locale, no_tracing,
_2G, _4G, bigmemtest, forget,
)
from test.support import threading_helper
+from test.support.warnings_helper import save_restore_warnings_filters
from pickle import bytes_types
+
+# bpo-41003: Save/restore warnings filters to leave them unchanged.
+# Ignore filters installed by numpy.
+try:
+ with save_restore_warnings_filters():
+ import numpy as np
+except ImportError:
+ np = None
+
+
requires_32b = unittest.skipUnless(sys.maxsize < 2**32,
"test is only meaningful on 32-bit builds")
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
--- /dev/null
+Fix ``test_copyreg`` when ``numpy`` is installed: ``test.pickletester`` now
+saves/restores warnings filters when importing ``numpy``, to ignore filters
+installed by ``numpy``.