[Python-checkins] cpython: Fix test_compilepath() of test_compileall

victor.stinner python-checkins at python.org
Mon Jan 18 05:26:52 EST 2016


https://hg.python.org/cpython/rev/c6a0f424837a
changeset:   99958:c6a0f424837a
parent:      99956:bc625fce0aee
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Jan 18 11:25:50 2016 +0100
summary:
  Fix test_compilepath() of test_compileall

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.

files:
  Lib/test/test_compileall.py |  12 ++++++++++++
  1 files changed, 12 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py
--- a/Lib/test/test_compileall.py
+++ b/Lib/test/test_compileall.py
@@ -103,6 +103,18 @@
                                                 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]):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list