https://github.com/python/cpython/commit/72ba9549898f219e70a0dd2ec848a092d6e4a9c9
commit: 72ba9549898f219e70a0dd2ec848a092d6e4a9c9
branch: main
author: sobolevn <[email protected]>
committer: sobolevn <[email protected]>
date: 2026-11-12T13:07:48+03:00
summary:
gh-161617: Fix `test_clinic`, `test_tools`, `test_generated_cases` with lazy
imports (#161618)
files:
M Lib/test/lazy_imports_all_exclude.txt
M Lib/test/support/import_helper.py
M Lib/test/test_tools/__init__.py
diff --git a/Lib/test/lazy_imports_all_exclude.txt
b/Lib/test/lazy_imports_all_exclude.txt
index 864d723fe56b11..e5519323e88e38 100644
--- a/Lib/test/lazy_imports_all_exclude.txt
+++ b/Lib/test/lazy_imports_all_exclude.txt
@@ -19,10 +19,8 @@
test.test_inspect.test_inspect
test___all__
test__interpreters
-test_clinic
test_crossinterp
test_datetime
-test_generated_cases
test_import
test_importlib
test_json
@@ -32,6 +30,5 @@ test_profiling
test_pyrepl
test_subprocess
test_symtable
-test_tools
test_type_annotations
test_unittest
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]