[Python-checkins] r75467 - in python/trunk/Lib/test: test_imp.py test_import.py

nick.coghlan python-checkins at python.org
Sat Oct 17 17:57:42 CEST 2009


Author: nick.coghlan
Date: Sat Oct 17 17:57:42 2009
New Revision: 75467

Log:
Avoid replacing existing modules and sys.path in import tests

Modified:
   python/trunk/Lib/test/test_imp.py
   python/trunk/Lib/test/test_import.py

Modified: python/trunk/Lib/test/test_imp.py
==============================================================================
--- python/trunk/Lib/test/test_imp.py	(original)
+++ python/trunk/Lib/test/test_imp.py	Sat Oct 17 17:57:42 2009
@@ -43,16 +43,19 @@
     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():

Modified: python/trunk/Lib/test/test_import.py
==============================================================================
--- python/trunk/Lib/test/test_import.py	(original)
+++ python/trunk/Lib/test/test_import.py	Sat Oct 17 17:57:42 2009
@@ -8,7 +8,7 @@
 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 @@
     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 @@
 
     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):


More information about the Python-checkins mailing list