Skip to content

Commit 09e0325

Browse files
committed
Fix doc string and add new test
1 parent 7063fa2 commit 09e0325

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
@@ -701,7 +701,7 @@ def test_missing_lazy_submodule_raises_module_not_found_error(self):
701701
assert_python_ok("-c", code)
702702

703703
def test_non_package_lazily_imported(self):
704-
"""Accessing a nonexistent lazy submodule via parent attr raises AttributeError."""
704+
"""Accessing a nonexistent lazy submodule via parent attr raises ModuleNotFoundError."""
705705
code = textwrap.dedent("""
706706
lazy import math.pi
707707
@@ -714,6 +714,20 @@ def test_non_package_lazily_imported(self):
714714
""")
715715
assert_python_ok("-c", code)
716716

717+
def test_missing_attribute_raises_import_error(self):
718+
"""Accessing a nonexistent lazy submodule via from import raises ImportError."""
719+
code = textwrap.dedent("""
720+
lazy from sys import doesnotexist
721+
722+
try:
723+
_ = doesnotexist
724+
except ImportError:
725+
pass
726+
else:
727+
raise AssertionError("ImportError was not raised")
728+
""")
729+
assert_python_ok("-c", code)
730+
717731
def test_missing_lazy_from_import_shows_chained_traceback(self):
718732
"""Accessing missing attribute from lazy from-import should chain errors."""
719733
code = textwrap.dedent("""

0 commit comments

Comments
 (0)