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.
This commit is contained in:
Victor Stinner 2016-01-18 11:25:50 +01:00
parent 4b5b06203e
commit c437d0cb4e

View 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]):