Skip to content

Commit c437d0c

Browse files
committed
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.
1 parent 4b5b062 commit c437d0c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Lib/test/test_compileall.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ def test_compile_files(self):
103103
force=False, quiet=2))
104104

105105
def test_compile_path(self):
106+
# Exclude Lib/test/ which contains invalid Python files like
107+
# Lib/test/badsyntax_pep3120.py
108+
testdir = os.path.realpath(os.path.dirname(__file__))
109+
if testdir in sys.path:
110+
self.addCleanup(setattr, sys, 'path', sys.path)
111+
112+
sys.path = list(sys.path)
113+
try:
114+
sys.path.remove(testdir)
115+
except ValueError:
116+
pass
117+
106118
self.assertTrue(compileall.compile_path(quiet=2))
107119

108120
with test.test_importlib.util.import_state(path=[self.directory]):

0 commit comments

Comments
 (0)