[New-bugs-announce] [issue37473] importlib: Remove libregrtest hack: "We import importlib *ASAP* in order to test #15386"
STINNER Victor
report at bugs.python.org
Mon Jul 1 11:24:52 EDT 2019
New submission from STINNER Victor <vstinner at redhat.com>:
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 at 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
----------
components: Tests
messages: 347032
nosy: brett.cannon, ncoghlan, vstinner
priority: normal
severity: normal
status: open
title: importlib: Remove libregrtest hack: "We import importlib *ASAP* in order to test #15386"
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37473>
_______________________________________
More information about the New-bugs-announce
mailing list