Commit b9d48323 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-40055: test_distutils leaves warnings filters unchanged (GH-20095)

distutils.tests now saves/restores warnings filters to leave them
unchanged. Importing tests imports docutils which imports
pkg_resources which adds a warnings filter.
parent a672328f
...@@ -15,6 +15,7 @@ by import rather than matching pre-defined names. ...@@ -15,6 +15,7 @@ by import rather than matching pre-defined names.
import os import os
import sys import sys
import unittest import unittest
import warnings
from test.support import run_unittest from test.support import run_unittest
...@@ -22,6 +23,7 @@ here = os.path.dirname(__file__) or os.curdir ...@@ -22,6 +23,7 @@ here = os.path.dirname(__file__) or os.curdir
def test_suite(): def test_suite():
old_filters = warnings.filters[:]
suite = unittest.TestSuite() suite = unittest.TestSuite()
for fn in os.listdir(here): for fn in os.listdir(here):
if fn.startswith("test") and fn.endswith(".py"): if fn.startswith("test") and fn.endswith(".py"):
...@@ -29,6 +31,10 @@ def test_suite(): ...@@ -29,6 +31,10 @@ def test_suite():
__import__(modname) __import__(modname)
module = sys.modules[modname] module = sys.modules[modname]
suite.addTest(module.test_suite()) 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 return suite
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment