[Python-checkins] cpython: Issue #18864: Don't try and use unittest as a testing module for
brett.cannon
python-checkins at python.org
Fri Nov 22 20:38:14 CET 2013
http://hg.python.org/cpython/rev/98bab4a03120
changeset: 87357:98bab4a03120
user: Brett Cannon <brett at python.org>
date: Fri Nov 22 14:38:09 2013 -0500
summary:
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.
files:
Lib/test/test_importlib/builtin/test_loader.py | 24 +++++++--
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
--- a/Lib/test/test_importlib/builtin/test_loader.py
+++ b/Lib/test/test_importlib/builtin/test_loader.py
@@ -63,10 +63,18 @@
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 @@
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,
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list