]> granicus.if.org Git - python/commitdiff
Fix test_compilepath() of test_compileall
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 18 Jan 2016 10:25:50 +0000 (11:25 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 18 Jan 2016 10:25:50 +0000 (11:25 +0100)
Issue #26101: Exclude Lib/test/ from sys.path in test_compilepath(). The
directory contains invalid Python files like Lib/test/badsyntax_pep3120.py,
whereas the test ensures that all files can be compiled.

Lib/test/test_compileall.py

index 439c125edb3de7f1e54a239de1883628cb5eff04..6d8a86352fc5e382b11c5cf1199f9b99e5ca1aef 100644 (file)
@@ -103,6 +103,18 @@ 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]):