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 @@ -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 ("""
You can’t perform that action at this time.
0 commit comments