diff options
author | Brett Cannon <brett@python.org> | 2014-05-23 16:30:37 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2014-05-23 16:30:37 (GMT) |
commit | 8447c703d1fd0107a52b15de7ce3a7056e1ec160 (patch) | |
tree | 1c6db7c398072ba929180cab46acf52bad84fec0 /Lib/test/test_pkgutil.py | |
parent | 065266450ea5519a43bcc199e48d304f1e7038e8 (diff) | |
download | cpython-8447c703d1fd0107a52b15de7ce3a7056e1ec160.zip cpython-8447c703d1fd0107a52b15de7ce3a7056e1ec160.tar.gz cpython-8447c703d1fd0107a52b15de7ce3a7056e1ec160.tar.bz2 |
Issue #14710: Fix both pkgutil.find_loader() and get_loader() to not
raise an exception when a module doesn't exist.
Thanks to Pavel Aslanov for the bug report.
Diffstat (limited to 'Lib/test/test_pkgutil.py')
-rw-r--r-- | Lib/test/test_pkgutil.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_pkgutil.py b/Lib/test/test_pkgutil.py index 9704156..e0c8635de 100644 --- a/Lib/test/test_pkgutil.py +++ b/Lib/test/test_pkgutil.py @@ -363,6 +363,20 @@ class ImportlibMigrationTests(unittest.TestCase): loader = pkgutil.get_loader(name) self.assertIsNone(loader) + def test_get_loader_None_in_sys_modules(self): + name = 'totally bogus' + sys.modules[name] = None + try: + loader = pkgutil.get_loader(name) + finally: + del sys.modules[name] + self.assertIsNone(loader) + + def test_find_loader_missing_module(self): + name = 'totally bogus' + loader = pkgutil.find_loader(name) + self.assertIsNone(loader) + def test_find_loader_avoids_emulation(self): with check_warnings() as w: self.assertIsNotNone(pkgutil.find_loader("sys")) |