diff options
author | Brett Cannon <brett@python.org> | 2016-06-25 17:50:24 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2016-06-25 17:50:24 (GMT) |
commit | da037616b10fc12a213e67711065f8123fb98cef (patch) | |
tree | 24fdcc554f0a01dd3c84070669f4f343fedaf229 /Lib | |
parent | b466f8facf9ae8e893c30b7a7a76a8333b59d5c7 (diff) | |
parent | e92dc9c23da8cb11f922f28353e6a58928aa5c71 (diff) | |
download | cpython-da037616b10fc12a213e67711065f8123fb98cef.zip cpython-da037616b10fc12a213e67711065f8123fb98cef.tar.gz cpython-da037616b10fc12a213e67711065f8123fb98cef.tar.bz2 |
Merge from 3.5
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/importlib/util.py | 2 | ||||
-rw-r--r-- | Lib/test/test_importlib/test_lazy.py | 16 |
2 files changed, 14 insertions, 4 deletions
diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py index af781fd..a9d0f1e 100644 --- a/Lib/importlib/util.py +++ b/Lib/importlib/util.py @@ -241,7 +241,7 @@ class _LazyModule(types.ModuleType): if id(self) != id(sys.modules[original_name]): msg = ('module object for {!r} substituted in sys.modules ' 'during a lazy load') - raise ValueError(msg.format(original_name)) + raise ValueError(msg.format(original_name)) # Update after loading since that's what would happen in an eager # loading situation. self.__dict__.update(attrs_updated) diff --git a/Lib/test/test_importlib/test_lazy.py b/Lib/test/test_importlib/test_lazy.py index 774b7a4..cc383c2 100644 --- a/Lib/test/test_importlib/test_lazy.py +++ b/Lib/test/test_importlib/test_lazy.py @@ -1,6 +1,8 @@ import importlib from importlib import abc from importlib import util +import sys +import types import unittest from . import util as test_util @@ -122,12 +124,20 @@ class LazyLoaderTests(unittest.TestCase): self.assertFalse(hasattr(module, '__name__')) def test_module_substitution_error(self): - source_code = 'import sys; sys.modules[__name__] = 42' - module = self.new_module(source_code) with test_util.uncache(TestingImporter.module_name): - with self.assertRaises(ValueError): + fresh_module = types.ModuleType(TestingImporter.module_name) + sys.modules[TestingImporter.module_name] = fresh_module + module = self.new_module() + with self.assertRaisesRegex(ValueError, "substituted"): module.__name__ + def test_module_already_in_sys(self): + with test_util.uncache(TestingImporter.module_name): + module = self.new_module() + sys.modules[TestingImporter.module_name] = module + # Force the load; just care that no exception is raised. + module.__name__ + if __name__ == '__main__': unittest.main() |