@@ -88,6 +88,26 @@ def test_basic_used(self):
8888 import test .test_lazy_import .data .basic_used
8989 self .assertIn ("test.test_lazy_import.data.basic2" , sys .modules )
9090
91+ @support .requires_subprocess ()
92+ def test_from_import_with_module_getattr (self ):
93+ """Lazy from import should respect module-level __getattr__."""
94+ code = textwrap .dedent ("""
95+ lazy from test.test_lazy_import.data.module_with_getattr import dynamic_attr
96+ assert dynamic_attr == "from_getattr"
97+ """ )
98+ assert_python_ok ("-c" , code )
99+
100+ @support .requires_subprocess ()
101+ def test_from_import_with_imported_module_getattr (self ):
102+ """Lazy from import should not shadow an imported module's __getattr__."""
103+ code = textwrap .dedent ("""
104+ import test.test_lazy_import.data.module_with_getattr as mod
105+ lazy from test.test_lazy_import.data.module_with_getattr import dynamic_attr
106+ assert dynamic_attr == "from_getattr"
107+ assert mod.dynamic_attr == "from_getattr"
108+ """ )
109+ assert_python_ok ("-c" , code )
110+
91111
92112class GlobalLazyImportModeTests (unittest .TestCase ):
93113 """Tests for sys.set_lazy_imports() global mode control."""
@@ -385,6 +405,17 @@ def test_lazy_import_pkg_cross_import(self):
385405 self .assertEqual (type (g ["x" ]), int )
386406 self .assertEqual (type (g ["b" ]), types .LazyImportType )
387407
408+ @support .requires_subprocess ()
409+ def test_package_from_import_with_module_getattr (self ):
410+ """Lazy from import should respect a package's __getattr__."""
411+ code = textwrap .dedent ("""
412+ import test.test_lazy_import.data.pkg as pkg
413+ lazy from test.test_lazy_import.data.pkg import dynamic_attr
414+ assert dynamic_attr == "from_getattr"
415+ assert pkg.dynamic_attr == "from_getattr"
416+ """ )
417+ assert_python_ok ("-c" , code )
418+
388419
389420class DunderLazyImportTests (unittest .TestCase ):
390421 """Tests for __lazy_import__ builtin function."""
0 commit comments