diff options
author | Garvit Khatri <garvit.khatri@zomato.com> | 2017-05-24 22:19:50 (GMT) |
---|---|---|
committer | Brett Cannon <brettcannon@users.noreply.github.com> | 2017-05-24 22:19:50 (GMT) |
commit | 94987826e89e8a89c20f081e18be33fc840e6203 (patch) | |
tree | 2520853181960af114e49c6635ee071b03e2af3c /Lib/test/test_importlib/test_api.py | |
parent | 3480ef9dd3177be8c0d71a74853dca6e5b11fbe1 (diff) | |
download | cpython-94987826e89e8a89c20f081e18be33fc840e6203.zip cpython-94987826e89e8a89c20f081e18be33fc840e6203.tar.gz cpython-94987826e89e8a89c20f081e18be33fc840e6203.tar.bz2 |
bpo-29851: Have importlib.reload() raise ImportError if the module's spec is not found (GH-972)
Diffstat (limited to 'Lib/test/test_importlib/test_api.py')
-rw-r--r-- | Lib/test/test_importlib/test_api.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py index b0a94aa..50dbfe1 100644 --- a/Lib/test/test_importlib/test_api.py +++ b/Lib/test/test_importlib/test_api.py @@ -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 |