@@ -68,15 +68,7 @@ def setUp(self):
6868 def tearDown (self ):
6969 unload (TESTFN )
7070
71- def test_import_raises_ModuleNotFoundError (self ):
72- with self .assertRaises (ModuleNotFoundError ):
73- import something_that_should_not_exist_anywhere
74-
75- def test_from_import_raises_ModuleNotFoundError (self ):
76- with self .assertRaises (ModuleNotFoundError ):
77- from something_that_should_not_exist_anywhere import blah
78- with self .assertRaises (ModuleNotFoundError ):
79- from importlib import something_that_should_not_exist_anywhere
71+ setUp = tearDown
8072
8173 def test_case_sensitivity (self ):
8274 # Brief digression to test that import is case-sensitive: if we got
@@ -495,7 +487,7 @@ def test_foreign_code(self):
495487 header = f .read (12 )
496488 code = marshal .load (f )
497489 constants = list (code .co_consts )
498- foreign_code = importlib . import_module .__code__
490+ foreign_code = test_main .__code__
499491 pos = constants .index (1 )
500492 constants [pos ] = foreign_code
501493 code = type (code )(code .co_argcount , code .co_kwonlyargcount ,
@@ -1021,5 +1013,16 @@ def load_module(*args):
10211013 importlib .SourceLoader .load_module = old_load_module
10221014
10231015
1016+ def test_main (verbose = None ):
1017+ run_unittest (ImportTests , PycacheTests , FilePermissionTests ,
1018+ PycRewritingTests , PathsTests , RelativeImportTests ,
1019+ OverridingImportBuiltinTests ,
1020+ ImportlibBootstrapTests ,
1021+ TestSymbolicallyLinkedPackage ,
1022+ ImportTracebackTests )
1023+
1024+
10241025if __name__ == '__main__' :
1025- unittest .main ()
1026+ # Test needs to be a package, so we can do relative imports.
1027+ from test .test_import import test_main
1028+ test_main ()
0 commit comments