diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py index 6368ef02253..8f425df133b 100644 --- a/Lib/test/test___all__.py +++ b/Lib/test/test___all__.py @@ -62,6 +62,12 @@ class AllTest(unittest.TestCase): self.assertEqual(keys, all_set, "in module {}".format(modname)) def walk_modules(self, basedir, modpath): + if modpath == 'distutils.': + # gh-135374: when setuptools is installed, it now replaces + # 'distutils' with its own version. + # In a security-fix only branch of CPython, + # skip the __all__ test rather than deal with the fallout. + return for fn in sorted(os.listdir(basedir)): path = os.path.join(basedir, fn) if os.path.isdir(path): diff --git a/Lib/test/test_sundry.py b/Lib/test/test_sundry.py index 007d68817c6..f27450e4a35 100644 --- a/Lib/test/test_sundry.py +++ b/Lib/test/test_sundry.py @@ -6,6 +6,7 @@ from test import support from test.support import import_helper from test.support import warnings_helper import unittest +import sys class TestUntestedModules(unittest.TestCase): def test_untested_modules_can_be_imported(self): @@ -20,6 +21,32 @@ class TestUntestedModules(unittest.TestCase): self.fail('{} has tests even though test_sundry claims ' 'otherwise'.format(name)) + import html.entities + + try: + import tty # Not available on Windows + except ImportError: + if support.verbose: + print("skipping tty") + + def test_distutils_modules(self): + with warnings_helper.check_warnings(quiet=True): + + path_copy = sys.path[:] + import distutils + if '_distutils_hack' in sys.modules: + # gh-135374: when 'setuptools' is installed, it now replaces + # 'distutils' with its own version. + # This imports '_distutils_hack' and modifies sys.path. + # The setuptols version of distutils also does not include some + # of the modules tested here. + + # Undo the path modifications and skip the test. + + sys.path[:] = path_copy + raise unittest.SkipTest( + 'setuptools has replaced distutils with its own version') + import distutils.bcppcompiler import distutils.ccompiler import distutils.cygwinccompiler @@ -45,13 +72,6 @@ class TestUntestedModules(unittest.TestCase): import distutils.command.sdist import distutils.command.upload - import html.entities - - try: - import tty # Not available on Windows - except ImportError: - if support.verbose: - print("skipping tty") if __name__ == "__main__":