]> granicus.if.org Git - python/commitdiff
Avoid replacing existing modules and sys.path in import tests
authorNick Coghlan <ncoghlan@gmail.com>
Sat, 17 Oct 2009 15:57:42 +0000 (15:57 +0000)
committerNick Coghlan <ncoghlan@gmail.com>
Sat, 17 Oct 2009 15:57:42 +0000 (15:57 +0000)
Lib/test/test_imp.py
Lib/test/test_import.py

index f4a1649698c0f9bbc7962588b3e67f3c2a13ba0c..1e629409398bea30dcc465d2e40b432fb490f31d 100644 (file)
@@ -43,16 +43,19 @@ class ReloadTests(unittest.TestCase):
     reload()."""
 
     def test_source(self):
-        import os
-        imp.reload(os)
+        with test_support.CleanImport('os'):
+            import os
+            imp.reload(os)
 
     def test_extension(self):
-        import time
-        imp.reload(time)
+        with test_support.CleanImport('time'):
+            import time
+            imp.reload(time)
 
     def test_builtin(self):
-        import marshal
-        imp.reload(marshal)
+        with test_support.CleanImport('marshal'):
+            import marshal
+            imp.reload(marshal)
 
 
 def test_main():
index 80ac60db93269bd20b953aaf685d60612d898f0c..4e0a6860fcf878fb5a1b8720b78405290b501bfc 100644 (file)
@@ -8,7 +8,7 @@ import py_compile
 import warnings
 import marshal
 from test.test_support import (unlink, TESTFN, unload, run_unittest,
-    check_warnings, TestFailed)
+    check_warnings, TestFailed, CleanImport)
 
 
 def remove_files(name):
@@ -122,8 +122,9 @@ 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)
+        with CleanImport("os"):
+            x = imp.find_module("os")
+            os = imp.load_module("os", *x)
 
     def test_module_with_large_stack(self, module='longlist'):
         # create module w/list of 65000 elements to test bug #561858
@@ -361,7 +362,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):