summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib/test_api.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-03-13 18:09:08 (GMT)
committerBrett Cannon <brett@python.org>2013-03-13 18:09:08 (GMT)
commit327992330e13cd6663faa8400f9ff46daab828b0 (patch)
tree922c440ad749973a0d7cef94ffc46eae0ddaa92b /Lib/test/test_importlib/test_api.py
parent542308eae7a95ae62aa1bc8e8c6c2f8a3695ae34 (diff)
downloadcpython-327992330e13cd6663faa8400f9ff46daab828b0.zip
cpython-327992330e13cd6663faa8400f9ff46daab828b0.tar.gz
cpython-327992330e13cd6663faa8400f9ff46daab828b0.tar.bz2
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).
Diffstat (limited to 'Lib/test/test_importlib/test_api.py')
-rw-r--r--Lib/test/test_importlib/test_api.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py
index f66e257..ac88b2b 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'