https://github.com/python/cpython/commit/c56b0138d9390fe32b1342120ae0628d6d902f66
commit: c56b0138d9390fe32b1342120ae0628d6d902f66
branch: main
author: sobolevn <[email protected]>
committer: sobolevn <[email protected]>
date: 2026-11-08T12:39:21Z
summary:
gh-161602: Enable `test_builtin` test with `PYTHON_LAZY_IMPORTS=all` (#161603)
files:
M Lib/test/lazy_imports_all_exclude.txt
M Lib/test/test_builtin.py
diff --git a/Lib/test/lazy_imports_all_exclude.txt
b/Lib/test/lazy_imports_all_exclude.txt
index 8d303858139b9f..864d723fe56b11 100644
--- a/Lib/test/lazy_imports_all_exclude.txt
+++ b/Lib/test/lazy_imports_all_exclude.txt
@@ -19,7 +19,6 @@
test.test_inspect.test_inspect
test___all__
test__interpreters
-test_builtin
test_clinic
test_crossinterp
test_datetime
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 501f482570ac32..d21de4adc2a98d 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -1052,10 +1052,16 @@ def test_eval_builtins_mapping(self):
eval, code, ns)
def test_exec_builtins_mapping_import(self):
+ # Globally enabled lazy imports do use different import hooks:
+ if sys.get_lazy_imports() == "all":
+ hook = "__lazy_import__"
+ else:
+ hook = "__import__"
+
code = compile("import foo.bar", "test", "exec")
ns = {'__builtins__': types.MappingProxyType({})}
- self.assertRaisesRegex(ImportError, "__import__ not found", exec,
code, ns)
- ns = {'__builtins__': types.MappingProxyType({'__import__': lambda
*args: args})}
+ self.assertRaisesRegex(ImportError, f"{hook} not found", exec, code,
ns)
+ ns = {'__builtins__': types.MappingProxyType({hook: lambda *args:
args})}
exec(code, ns)
self.assertEqual(ns['foo'], ('foo.bar', ns, ns, None, 0))
_______________________________________________
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]