Issue #15210: If _frozen_importlib is not found in sys.modules by
importlib.__init__, then catch the KeyError raised, not ImportError.
This commit is contained in:
parent
1e331560ee
commit
8e2f5564b3
|
@ -7,7 +7,7 @@ import sys
|
|||
|
||||
try:
|
||||
_bootstrap = sys.modules['_frozen_importlib']
|
||||
except ImportError:
|
||||
except KeyError:
|
||||
from . import _bootstrap
|
||||
_bootstrap._setup(sys, imp)
|
||||
else:
|
||||
|
|
|
@ -160,9 +160,30 @@ class InvalidateCacheTests(unittest.TestCase):
|
|||
importlib.invalidate_caches() # Shouldn't trigger an exception.
|
||||
|
||||
|
||||
class FrozenImportlibTests(unittest.TestCase):
|
||||
|
||||
def test_no_frozen_importlib(self):
|
||||
# Should be able to import w/o _frozen_importlib being defined.
|
||||
modules = {}
|
||||
for name in ('importlib', 'importlib.__init__', 'importlib._bootstrap',
|
||||
'_frozen_importlib'):
|
||||
try:
|
||||
modules[name] = sys.modules[name]
|
||||
del sys.modules[name]
|
||||
except KeyError:
|
||||
continue
|
||||
modules['_frozen_importlib'] = None
|
||||
import importlib
|
||||
for name, module in modules.items():
|
||||
sys.modules[name] = module
|
||||
|
||||
|
||||
def test_main():
|
||||
from test.support import run_unittest
|
||||
run_unittest(ImportModuleTests, FindLoaderTests, InvalidateCacheTests)
|
||||
run_unittest(ImportModuleTests,
|
||||
FindLoaderTests,
|
||||
InvalidateCacheTests,
|
||||
FrozenImportlibTests)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue