https://github.com/python/cpython/commit/5ab502cdf96366ad31a2d855fdce30d99d9e9c25
commit: 5ab502cdf96366ad31a2d855fdce30d99d9e9c25
branch: 3.15
author: sobolevn <[email protected]>
committer: sobolevn <[email protected]>
date: 2026-11-08T13:23:58Z
summary:
[3.15] gh-161602: Enable `test_builtin` test with `PYTHON_LAZY_IMPORTS=all`
(GH-161603) (#161605)
(cherry picked from commit c56b0138d9390fe32b1342120ae0628d6d902f66)
files:
M Lib/test/test_builtin.py
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index d7c1e080063cac..7eb6a5309bf0e0 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]