]> granicus.if.org Git - python/commitdiff
Issue #27322: Set sys.path to a temp dir in test_compile_path
authorBerker Peksag <berker.peksag@gmail.com>
Wed, 28 Sep 2016 14:38:53 +0000 (17:38 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Wed, 28 Sep 2016 14:38:53 +0000 (17:38 +0300)
Lib/test/test_compileall.py

index 9b424a7250617d78f8420035098d09ad8fe878b4..1f05e78c2303b33812e5ddfc1540d01e45ee55b2 100644 (file)
@@ -103,19 +103,8 @@ class CompileallTests(unittest.TestCase):
                                                 force=False, quiet=2))
 
     def test_compile_path(self):
-        # Exclude Lib/test/ which contains invalid Python files like
-        # Lib/test/badsyntax_pep3120.py
-        testdir = os.path.realpath(os.path.dirname(__file__))
-        if testdir in sys.path:
-            self.addCleanup(setattr, sys, 'path', sys.path)
-
-            sys.path = list(sys.path)
-            try:
-                sys.path.remove(testdir)
-            except ValueError:
-                pass
-
-        self.assertTrue(compileall.compile_path(quiet=2))
+        with test.test_importlib.util.import_state(path=[self.directory]):
+            self.assertTrue(compileall.compile_path(quiet=2))
 
         with test.test_importlib.util.import_state(path=[self.directory]):
             self.add_bad_source_file()