diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2009-10-17 15:57:42 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2009-10-17 15:57:42 (GMT) |
commit | 788d7667cb0c95756c296fec0f863f8870118820 (patch) | |
tree | 821aae2674c1f35d9335782a103d7c13a0c62ced | |
parent | 8157e19e8fe311e8f18542750125a83cc97943f4 (diff) | |
download | cpython-788d7667cb0c95756c296fec0f863f8870118820.zip cpython-788d7667cb0c95756c296fec0f863f8870118820.tar.gz cpython-788d7667cb0c95756c296fec0f863f8870118820.tar.bz2 |
Avoid replacing existing modules and sys.path in import tests
-rw-r--r-- | Lib/test/test_imp.py | 15 | ||||
-rw-r--r-- | Lib/test/test_import.py | 9 |
2 files changed, 14 insertions, 10 deletions
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index f4a1649..1e62940 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -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(): diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index 80ac60d..4e0a686 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -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): |