bpo-29851: Have importlib.reload() raise ImportError if the module's spec is not found (GH-972)

This commit is contained in:
Garvit Khatri 2017-05-25 03:49:50 +05:30 committed by Brett Cannon
parent 3480ef9dd3
commit 94987826e8
5 changed files with 21 additions and 2 deletions

View file

@ -197,8 +197,6 @@ class FindLoaderPEP302Tests(FindLoaderTests):
class ReloadTests:
"""Test module reloading for builtin and extension modules."""
def test_reload_modules(self):
for mod in ('tokenize', 'time', 'marshal'):
with self.subTest(module=mod):
@ -361,6 +359,18 @@ class ReloadTests:
reloaded = self.init.reload(ham)
self.assertIs(reloaded, ham)
def test_module_missing_spec(self):
#Test that reload() throws ModuleNotFounderror when reloading
# a module who's missing a spec. (bpo-29851)
name = 'spam'
with test_util.uncache(name):
module = sys.modules[name] = types.ModuleType(name)
# Sanity check by attempting an import.
module = self.init.import_module(name)
self.assertIsNone(module.__spec__)
with self.assertRaises(ModuleNotFoundError):
self.init.reload(module)
(Frozen_ReloadTests,
Source_ReloadTests