diff options
| author | Victor Stinner <vstinner@python.org> | 2020-06-17 18:07:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-17 18:07:13 +0200 |
| commit | 4b54a8a038d5f9f2ead224b030f87f393d57d40b (patch) | |
| tree | 13f1edb55d7af6da5bfcd46160c98b8b969f4e3f | |
| parent | 5210488f65e41038e5721d31792fae784c39d649 (diff) | |
| download | python-setuptools-git-4b54a8a038d5f9f2ead224b030f87f393d57d40b.tar.gz | |
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.
| -rw-r--r-- | tests/__init__.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/tests/__init__.py b/tests/__init__.py index 5d2e69e3..16d011fd 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -15,26 +15,25 @@ by import rather than matching pre-defined names. 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 |
