From bea9dae30a1128142ba52bdf38632516270d521b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 24 Mar 2020 17:52:52 +0100 Subject: [PATCH] bpo-40055: distutils tests now disable docutils import Prevent docutils from being imported since "import docutils" can have side effects on tests. For example, it imports pkg_resources which alters warnings filters. --- Lib/distutils/tests/__init__.py | 6 ++++++ Lib/distutils/tests/test_check.py | 1 + Lib/distutils/tests/test_register.py | 10 ++++------ .../Tests/2020-03-24-17-54-08.bpo-40055.AKINUq.rst | 3 +++ 4 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2020-03-24-17-54-08.bpo-40055.AKINUq.rst diff --git a/Lib/distutils/tests/__init__.py b/Lib/distutils/tests/__init__.py index 1b939cbd5db2bf..d42b343f4e940d 100644 --- a/Lib/distutils/tests/__init__.py +++ b/Lib/distutils/tests/__init__.py @@ -18,6 +18,12 @@ from test.support import run_unittest +# bpo-40055: Prevent docutils from being imported to avoid depending on +# docutils. Import docutils can have side effects. For example, docutils +# imports pkg_resources which changes warnings filters. +sys.modules['docutils'] = None + + here = os.path.dirname(__file__) or os.curdir diff --git a/Lib/distutils/tests/test_check.py b/Lib/distutils/tests/test_check.py index e534aca1d47637..040a4da774be59 100644 --- a/Lib/distutils/tests/test_check.py +++ b/Lib/distutils/tests/test_check.py @@ -4,6 +4,7 @@ import unittest from test.support import run_unittest +# bpo-40055: distutils.tests prevents docutils from being imported from distutils.command.check import check, HAS_DOCUTILS from distutils.tests import support from distutils.errors import DistutilsSetupError diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py index e68b0af3ce0c3a..50beb267f9e0cc 100644 --- a/Lib/distutils/tests/test_register.py +++ b/Lib/distutils/tests/test_register.py @@ -14,10 +14,8 @@ from distutils.tests.test_config import BasePyPIRCCommandTestCase -try: - import docutils -except ImportError: - docutils = None +# bpo-40055: distutils.tests prevents docutils from being imported +from distutils.command.check import HAS_DOCUTILS PYPIRC_NOPASSWORD = """\ [distutils] @@ -204,7 +202,7 @@ def test_password_reset(self): self.assertEqual(headers['Content-length'], '290') self.assertIn(b'tarek', req.data) - @unittest.skipUnless(docutils is not None, 'needs docutils') + @unittest.skipUnless(HAS_DOCUTILS, 'needs docutils') def test_strict(self): # testing the script option # when on, the register command stops if @@ -270,7 +268,7 @@ def test_strict(self): finally: del register_module.input - @unittest.skipUnless(docutils is not None, 'needs docutils') + @unittest.skipUnless(HAS_DOCUTILS, 'needs docutils') def test_register_invalid_long_description(self): description = ':funkie:`str`' # mimic Sphinx-specific markup metadata = {'url': 'xxx', 'author': 'xxx', diff --git a/Misc/NEWS.d/next/Tests/2020-03-24-17-54-08.bpo-40055.AKINUq.rst b/Misc/NEWS.d/next/Tests/2020-03-24-17-54-08.bpo-40055.AKINUq.rst new file mode 100644 index 00000000000000..13b206a845d792 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2020-03-24-17-54-08.bpo-40055.AKINUq.rst @@ -0,0 +1,3 @@ +Distutils tests now prevent docutils from being imported since "import +docutils" can have side effects on tests. For example, it imports +pkg_resources which alters warnings filters.