@@ -52,7 +52,7 @@ def test_object(self):
5252 module = import_util .import_ ('module' , fromlist = ['attr' ])
5353 self .assertEqual (module .__name__ , 'module' )
5454
55- def test_unexistent_object (self ):
55+ def test_nonexistent_object (self ):
5656 # [bad object]
5757 with util .mock_modules ('module' ) as importer :
5858 with util .import_state (meta_path = [importer ]):
@@ -69,6 +69,19 @@ def test_module_from_package(self):
6969 self .assertTrue (hasattr (module , 'module' ))
7070 self .assertEqual (module .module .__name__ , 'pkg.module' )
7171
72+ def test_module_from_package_triggers_ImportError (self ):
73+ # If a submodule causes an ImportError because it tries to import
74+ # a module which doesn't exist, that should let the ImportError
75+ # propagate.
76+ def module_code ():
77+ import i_do_not_exist
78+ with util .mock_modules ('pkg.__init__' , 'pkg.mod' ,
79+ module_code = {'pkg.mod' : module_code }) as importer :
80+ with util .import_state (meta_path = [importer ]):
81+ with self .assertRaises (ImportError ) as exc :
82+ import_util .import_ ('pkg' , fromlist = ['mod' ])
83+ self .assertEquals ('i_do_not_exist' , exc .exception .name )
84+
7285 def test_empty_string (self ):
7386 with util .mock_modules ('pkg.__init__' , 'pkg.mod' ) as importer :
7487 with util .import_state (meta_path = [importer ]):
0 commit comments