@@ -80,6 +80,25 @@ def test_from_import_missing_attr_raises_ImportError(self):
8080 with self .assertRaises (ImportError ):
8181 from importlib import something_that_should_not_exist_anywhere
8282
83+ def test_from_import_missing_attr_has_name_and_path (self ):
84+ with self .assertRaises (ImportError ) as cm :
85+ from os import i_dont_exist
86+ self .assertEqual (cm .exception .name , 'os' )
87+ self .assertEqual (cm .exception .path , os .__file__ )
88+
89+ def test_from_import_missing_attr_has_name (self ):
90+ with self .assertRaises (ImportError ) as cm :
91+ # _warning has no path as it's a built-in module.
92+ from _warning import i_dont_exist
93+ self .assertEqual (cm .exception .name , '_warning' )
94+ self .assertIsNone (cm .exception .path )
95+
96+ def test_from_import_missing_attr_path_is_canonical (self ):
97+ with self .assertRaises (ImportError ) as cm :
98+ from os .path import i_dont_exist
99+ self .assertIn (cm .exception .name , {'posixpath' , 'ntpath' })
100+ self .assertIsNotNone (cm .exception )
101+
83102 def test_case_sensitivity (self ):
84103 # Brief digression to test that import is case-sensitive: if we got
85104 # this far, we know for sure that "random" exists.
0 commit comments