[Python-checkins] bpo-37473: Don't import importlib ASAP in tests (GH-14661)

Victor Stinner webhook-mailer at python.org
Sun Jul 14 13:31:25 EDT 2019


https://github.com/python/cpython/commit/8b7db5a1114e2113a756bdf8877fbe366055c69a
commit: 8b7db5a1114e2113a756bdf8877fbe366055c69a
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2019-07-14T19:31:12+02:00
summary:

bpo-37473: Don't import importlib ASAP in tests (GH-14661)

bpo-15386, bpo-37473: test_import, regrtest and libregrtest no longer
import importlib as soon as possible, as the first import, "to test
bpo-15386".

It is tested by test_import.test_there_can_be_only_one().

Sort test_import imports.

files:
M Lib/test/libregrtest/__init__.py
M Lib/test/regrtest.py
M Lib/test/test_import/__init__.py

diff --git a/Lib/test/libregrtest/__init__.py b/Lib/test/libregrtest/__init__.py
index 3427b51b60af..5e8dba5dbde7 100644
--- a/Lib/test/libregrtest/__init__.py
+++ b/Lib/test/libregrtest/__init__.py
@@ -1,5 +1,2 @@
-# We import importlib *ASAP* in order to test #15386
-import importlib
-
 from test.libregrtest.cmdline import _parse_args, RESOURCE_NAMES, ALL_RESOURCES
 from test.libregrtest.main import main
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 21b0edfd073d..0ffb3ed454ed 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -6,9 +6,6 @@
 Run this script with -h or --help for documentation.
 """
 
-# We import importlib *ASAP* in order to test #15386
-import importlib
-
 import os
 import sys
 from test.libregrtest import main
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py
index 50406d9aa1d9..88746b4315f9 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -1,24 +1,22 @@
-# We import importlib *ASAP* in order to test #15386
-import importlib
+import builtins
+import contextlib
+import errno
+import glob
 import importlib.util
 from importlib._bootstrap_external import _get_sourcefile
-import builtins
 import marshal
 import os
 import py_compile
 import random
 import shutil
-import subprocess
 import stat
+import subprocess
 import sys
+import textwrap
 import threading
 import time
 import unittest
-import unittest.mock as mock
-import textwrap
-import errno
-import contextlib
-import glob
+from unittest import mock
 
 import test.support
 from test.support import (



More information about the Python-checkins mailing list