summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_import.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_import.py')
-rw-r--r--Lib/test/test_import.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
index 20c2d88..23967cb 100644
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -8,7 +8,8 @@ import py_compile
import warnings
import imp
import marshal
-from test.support import unlink, TESTFN, unload, run_unittest, TestFailed
+from test.support import (unlink, TESTFN, unload, run_unittest,
+ TestFailed, EnvironmentVarGuard)
def remove_files(name):
@@ -109,9 +110,22 @@ class ImportTest(unittest.TestCase):
def testImpModule(self):
# Verify that the imp module can correctly load and find .py files
- import imp
- x = imp.find_module("os")
- os = imp.load_module("os", *x)
+ import imp, os
+ # XXX (ncoghlan): It would be nice to use test_support.CleanImport
+ # here, but that breaks because the os module registers some
+ # handlers in copy_reg on import. Since CleanImport doesn't
+ # revert that registration, the module is left in a broken
+ # state after reversion. Reinitialising the module contents
+ # and just reverting os.environ to its previous state is an OK
+ # workaround
+ orig_path = os.path
+ orig_getenv = os.getenv
+ with EnvironmentVarGuard():
+ x = imp.find_module("os")
+ new_os = imp.load_module("os", *x)
+ self.assertIs(os, new_os)
+ self.assertIs(orig_path, new_os.path)
+ self.assertIsNot(orig_getenv, new_os.getenv)
def test_module_with_large_stack(self, module='longlist'):
# create module w/list of 65000 elements to test bug #561858
@@ -360,7 +374,7 @@ class PathsTests(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.path)
- sys.path = self.syspath
+ sys.path[:] = self.syspath
# http://bugs.python.org/issue1293
def test_trailing_slash(self):