File tree Expand file tree Collapse file tree
Lib/test/test_lazy_import Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ("""
You can’t perform that action at this time.
0 commit comments