This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients brett.cannon, ncoghlan, vstinner
Date 2019-07-01.15:24:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1561994692.63.0.367663564424.issue37473@roundup.psfhosted.org>
In-reply-to
Content
Lib/test/regrtest.py starts with:

# We import importlib *ASAP* in order to test #15386
import importlib

If there is a bug to test, would it be possible to write a dedicated test, rather than putting the test... in the code of the test runner?

Code added by bpo-15386:

commit be7e49fd820318509cd8b4dbde479c552f74ef62
Author: Nick Coghlan <ncoghlan@gmail.com>
Date:   Fri Jul 20 23:40:09 2012 +1000

    Close #15386: There was a loophole that meant importlib.machinery and imp would sometimes reference an uninitialised copy of importlib._bootstrap

(...)

diff --git a/Lib/runpy.py b/Lib/runpy.py
index d612727c6f..39c0e9f7dd 100644
--- a/Lib/runpy.py
+++ b/Lib/runpy.py
@@ -12,8 +12,8 @@ importers when locating support scripts as well as when importing modules.
 
 import os
 import sys
+import importlib.machinery # importlib first so we can test #15386 via -m
 import imp
-import importlib.machinery
 from pkgutil import read_code, get_loader, get_importer
 
 __all__ = [
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 28655f0e65..3c8359aca1 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -165,6 +165,9 @@ example, to run all the tests except for the gui tests, give the
 option '-uall,-gui'.
 """
 
+# We import importlib *ASAP* in order to test #15386
+import importlib
+
 import builtins
 import faulthandler
 import getopt
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
index 89ec8dcedc..51b52c7e0b 100644
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -1,8 +1,9 @@
+# We import importlib *ASAP* in order to test #15386
+import importlib
 import builtins
 import imp
 from importlib.test.import_ import test_suite as importlib_import_test_suite
 from importlib.test.import_ import util as importlib_util
-import importlib
 import marshal
 import os
 import platform
History
Date User Action Args
2019-07-01 15:24:52vstinnersetrecipients: + vstinner, brett.cannon, ncoghlan
2019-07-01 15:24:52vstinnersetmessageid: <1561994692.63.0.367663564424.issue37473@roundup.psfhosted.org>
2019-07-01 15:24:52vstinnerlinkissue37473 messages
2019-07-01 15:24:52vstinnercreate