https://github.com/python/cpython/commit/b24fd29bc834428c3bb02bdedfc943711aa5a7fc
commit: b24fd29bc834428c3bb02bdedfc943711aa5a7fc
branch: 3.15
author: sobolevn <[email protected]>
committer: sobolevn <[email protected]>
date: 2026-11-12T10:51:49Z
summary:
[3.15] gh-161617: Fix `test_clinic`, `test_tools`, `test_generated_cases` with
lazy imports (GH-161618) (#161865)
(cherry picked from commit 72ba9549898f219e70a0dd2ec848a092d6e4a9c9)
files:
M Lib/test/support/import_helper.py
M Lib/test/test_tools/__init__.py
diff --git a/Lib/test/support/import_helper.py
b/Lib/test/support/import_helper.py
index e8a3d176ad6943..962f65d8dcd14a 100644
--- a/Lib/test/support/import_helper.py
+++ b/Lib/test/support/import_helper.py
@@ -119,6 +119,20 @@ def frozen_modules(enabled=True):
_imp._override_frozen_modules_for_tests(0)
[email protected]
+def force_eager_imports():
+ """Force eager imports inside the context manager."""
+ original_lazy_imports_filter = sys.get_lazy_imports_filter()
+ sys.set_lazy_imports_filter(
+ # Tools must be imported eagerly under this context manager:
+ lambda importing, imported, fromlist: False
+ )
+ try:
+ yield
+ finally:
+ sys.set_lazy_imports_filter(original_lazy_imports_filter)
+
+
@contextlib.contextmanager
def multi_interp_extensions_check(enabled=True):
"""Force legacy modules to be allowed in subinterpreters (or not).
diff --git a/Lib/test/test_tools/__init__.py b/Lib/test/test_tools/__init__.py
index c4395c7c0ad0c9..310bf48c2ef03a 100644
--- a/Lib/test/test_tools/__init__.py
+++ b/Lib/test/test_tools/__init__.py
@@ -32,7 +32,10 @@ def skip_if_missing(tool=None):
@contextlib.contextmanager
def imports_under_tool(name, *subdirs):
tooldir = os.path.join(toolsdir, name, *subdirs)
- with import_helper.DirsOnSysPath(tooldir) as cm:
+ with (
+ import_helper.force_eager_imports(),
+ import_helper.DirsOnSysPath(tooldir) as cm,
+ ):
yield cm
def import_tool(toolname):
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]