"./python Lib/test/test_compileall.py" fails on test_compile_path() because the Lib/test/ directory is in sys.path and this directory contains invalid Python scripts like Lib/test/badsyntax_pep3120.py Attached patch fixes the issue by removing temporarely Lib/test/ from sys.path. Note: Python 3.5 doesn't test compileall.compile_path() which fails. The new test was added by the changeset 71f071f2e074 of the issue #25768.
A cleaner way to do what you're after is to use test_importlib.util.import_state() where you can pass in an explicit value for sys.path to be temporarily set. Otherwise I'm fine with the idea of the proposed change.
> A cleaner way to do what you're after is to use test_importlib.util.import_state() where you can pass in an explicit value for sys.path to be temporarily set. I would prefer to not couple test_importlib and test_compileall to keep tests independent. If you consider that it's worth, import_state() must be moved to test.support.