Skip to content

Commit afaa511

Browse files
committed
Fix doc string and add new test
1 parent 599c8d5 commit afaa511

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

Lib/test/test_lazy_import/__init__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ def test_missing_lazy_submodule_raises_module_not_found_error(self):
693693
assert_python_ok("-c", code)
694694

695695
def test_non_package_lazily_imported(self):
696-
"""Accessing a nonexistent lazy submodule via parent attr raises AttributeError."""
696+
"""Accessing a nonexistent lazy submodule via parent attr raises ModuleNotFoundError."""
697697
code = textwrap.dedent("""
698698
lazy import math.pi
699699
@@ -706,6 +706,20 @@ def test_non_package_lazily_imported(self):
706706
""")
707707
assert_python_ok("-c", code)
708708

709+
def test_missing_attribute_raises_import_error(self):
710+
"""Accessing a nonexistent lazy submodule via from import raises ImportError."""
711+
code = textwrap.dedent("""
712+
lazy from sys import doesnotexist
713+
714+
try:
715+
_ = doesnotexist
716+
except ImportError:
717+
pass
718+
else:
719+
raise AssertionError("ImportError was not raised")
720+
""")
721+
assert_python_ok("-c", code)
722+
709723
def test_missing_lazy_from_import_shows_chained_traceback(self):
710724
"""Accessing missing attribute from lazy from-import should chain errors."""
711725
code = textwrap.dedent("""

0 commit comments

Comments
 (0)