summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-11-22 19:38:09 (GMT)
committerBrett Cannon <brett@python.org>2013-11-22 19:38:09 (GMT)
commite0c3bd78c5934ccdaf78b810be0ea6557f44db83 (patch)
tree591b3bfaaa8105976f86ff4c303c8d854cba972a
parenta24348cec112a2fd0b7c993981e2428e73f261d9 (diff)
downloadcpython-e0c3bd78c5934ccdaf78b810be0ea6557f44db83.zip
cpython-e0c3bd78c5934ccdaf78b810be0ea6557f44db83.tar.gz
cpython-e0c3bd78c5934ccdaf78b810be0ea6557f44db83.tar.bz2
Issue #18864: Don't try and use unittest as a testing module for
built-in loading; leads to a reload scenario where attributes get set which are wrong after the test.
-rw-r--r--Lib/test/test_importlib/builtin/test_loader.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/Lib/test/test_importlib/builtin/test_loader.py b/Lib/test/test_importlib/builtin/test_loader.py
index 200188f..8e12813 100644
--- a/Lib/test/test_importlib/builtin/test_loader.py
+++ b/Lib/test/test_importlib/builtin/test_loader.py
@@ -63,10 +63,18 @@ class ExecModTests(abc.LoaderTests):
def test_already_imported(self):
# Using the name of a module already imported but not a built-in should
# still fail.
- assert hasattr(unittest, '__file__') # Not a built-in.
+ module_name = 'builtin_reload_test'
+ assert module_name not in sys.builtin_module_names
+ with util.uncache(module_name):
+ module = types.ModuleType(module_name)
+ spec = self.machinery.ModuleSpec(module_name,
+ self.machinery.BuiltinImporter,
+ origin='built-in')
+ module.__spec__ = spec
+ sys.modules[module_name] = module
with self.assertRaises(ImportError) as cm:
- self.load_spec('unittest')
- self.assertEqual(cm.exception.name, 'unittest')
+ self.machinery.BuiltinImporter.exec_module(module)
+ self.assertEqual(cm.exception.name, module_name)
Frozen_ExecModTests, Source_ExecModTests = util.test_both(ExecModTests,
@@ -120,10 +128,14 @@ class LoaderTests(abc.LoaderTests):
def test_already_imported(self):
# Using the name of a module already imported but not a built-in should
# still fail.
- assert hasattr(unittest, '__file__') # Not a built-in.
+ module_name = 'builtin_reload_test'
+ assert module_name not in sys.builtin_module_names
+ with util.uncache(module_name):
+ module = types.ModuleType(module_name)
+ sys.modules[module_name] = module
with self.assertRaises(ImportError) as cm:
- self.load_module('unittest')
- self.assertEqual(cm.exception.name, 'unittest')
+ self.load_module(module_name)
+ self.assertEqual(cm.exception.name, module_name)
Frozen_LoaderTests, Source_LoaderTests = util.test_both(LoaderTests,