Skip to content

Commit 91af026

Browse files
miss-islingtonencukouambvemmatyping
authored
[3.10] gh-135374: Adjust test for setuptools' replacement of distutils (GH-138796) (GH-139303)
ensurepip installs a bundled copy of distutils, which overrides the stdlib module. This affects several tests. This commit: - skips distutils in test___all__, as we're unlikely to break `__all__` in a security-fix-only branch (and if we do it's not much of a a big deal) - skips importability tests of distutils submodules if the setuptools hack is detected (cherry picked from commit 987af36) Co-authored-by: Petr Viktorin <[email protected]> Co-authored-by: Łukasz Langa <[email protected]> Co-authored-by: Emma Smith <[email protected]>
1 parent 7252d2b commit 91af026

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

Lib/test/test___all__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ def check_all(self, modname):
6262
self.assertEqual(keys, all_set, "in module {}".format(modname))
6363

6464
def walk_modules(self, basedir, modpath):
65+
if modpath == 'distutils.':
66+
# gh-135374: when setuptools is installed, it now replaces
67+
# 'distutils' with its own version.
68+
# In a security-fix only branch of CPython,
69+
# skip the __all__ test rather than deal with the fallout.
70+
return
6571
for fn in sorted(os.listdir(basedir)):
6672
path = os.path.join(basedir, fn)
6773
if os.path.isdir(path):

Lib/test/test_sundry.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from test.support import import_helper
77
from test.support import warnings_helper
88
import unittest
9+
import sys
910

1011
class TestUntestedModules(unittest.TestCase):
1112
def test_untested_modules_can_be_imported(self):
@@ -20,6 +21,32 @@ def test_untested_modules_can_be_imported(self):
2021
self.fail('{} has tests even though test_sundry claims '
2122
'otherwise'.format(name))
2223

24+
import html.entities
25+
26+
try:
27+
import tty # Not available on Windows
28+
except ImportError:
29+
if support.verbose:
30+
print("skipping tty")
31+
32+
def test_distutils_modules(self):
33+
with warnings_helper.check_warnings(quiet=True):
34+
35+
path_copy = sys.path[:]
36+
import distutils
37+
if '_distutils_hack' in sys.modules:
38+
# gh-135374: when 'setuptools' is installed, it now replaces
39+
# 'distutils' with its own version.
40+
# This imports '_distutils_hack' and modifies sys.path.
41+
# The setuptols version of distutils also does not include some
42+
# of the modules tested here.
43+
44+
# Undo the path modifications and skip the test.
45+
46+
sys.path[:] = path_copy
47+
raise unittest.SkipTest(
48+
'setuptools has replaced distutils with its own version')
49+
2350
import distutils.bcppcompiler
2451
import distutils.ccompiler
2552
import distutils.cygwinccompiler
@@ -45,13 +72,6 @@ def test_untested_modules_can_be_imported(self):
4572
import distutils.command.sdist
4673
import distutils.command.upload
4774

48-
import html.entities
49-
50-
try:
51-
import tty # Not available on Windows
52-
except ImportError:
53-
if support.verbose:
54-
print("skipping tty")
5575

5676

5777
if __name__ == "__main__":

0 commit comments

Comments
 (0)