From 327992330e13cd6663faa8400f9ff46daab828b0 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Wed, 13 Mar 2013 11:09:08 -0700 Subject: Issue #17099: Have importlib.find_loader() raise ValueError when __loader__ is not set on a module. This brings the exception in line with when __loader__ is None (which is equivalent to not having the attribute defined). --- Lib/test/test_importlib/test_api.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Lib/test/test_importlib/test_api.py') diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py index f66e257ee99..ac88b2bf9c1 100644 --- a/Lib/test/test_importlib/test_api.py +++ b/Lib/test/test_importlib/test_api.py @@ -116,6 +116,20 @@ class FindLoaderTests(unittest.TestCase): with self.assertRaises(ValueError): importlib.find_loader(name) + def test_sys_modules_loader_is_not_set(self): + # Should raise ValueError + # Issue #17099 + name = 'some_mod' + with util.uncache(name): + module = imp.new_module(name) + try: + del module.__loader__ + except AttributeError: + pass + sys.modules[name] = module + with self.assertRaises(ValueError): + importlib.find_loader(name) + def test_success(self): # Return the loader found on sys.meta_path. name = 'some_mod' -- cgit v1.2.3