Skip to content

Commit 6e57237

Browse files
authored
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.
1 parent 003708b commit 6e57237

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Lib/distutils/tests/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,26 @@
1515
import os
1616
import sys
1717
import unittest
18+
import warnings
1819
from test.support import run_unittest
1920

2021

2122
here = os.path.dirname(__file__) or os.curdir
2223

2324

2425
def test_suite():
26+
old_filters = warnings.filters[:]
2527
suite = unittest.TestSuite()
2628
for fn in os.listdir(here):
2729
if fn.startswith("test") and fn.endswith(".py"):
2830
modname = "distutils.tests." + fn[:-3]
2931
__import__(modname)
3032
module = sys.modules[modname]
3133
suite.addTest(module.test_suite())
34+
# bpo-40055: Save/restore warnings filters to leave them unchanged.
35+
# Importing tests imports docutils which imports pkg_resources which adds a
36+
# warnings filter.
37+
warnings.filters[:] = old_filters
3238
return suite
3339

3440

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
distutils.tests now saves/restores warnings filters to leave them unchanged.
2+
Importing tests imports docutils which imports pkg_resources which adds a
3+
warnings filter.

0 commit comments

Comments
 (0)