diff --git a/src/sage/tests/py3_syntax.py b/src/sage/tests/py3_syntax.py index e564860b48..86ab3725f9 100644 --- a/src/sage/tests/py3_syntax.py +++ b/src/sage/tests/py3_syntax.py @@ -179,15 +179,30 @@ class Python3SyntaxTest(SortedDirectoryWalkerABC): sage: py3_syntax = Python3SyntaxTest() sage: py3_syntax.test(src.name) Invalid Python 3 syntax found: - File "...py", line 1 - print "invalid print statement" - ^ - SyntaxError: Missing parentheses in call to 'print' + Missing parentheses in call to 'print'... sage: os.unlink(src.name) """ + + # compile all given files in memory, printing all errors + # inspired by the py_compile module (but without writing to file) + script = """ +import sys +import importlib.machinery +rv = 0 +for file in sys.argv[1:]: + loader = importlib.machinery.SourceFileLoader('', file) + source_bytes = loader.get_data(file) + try: + code = loader.source_to_code(source_bytes, file) + except Exception as err: + print(err) + rv = 1 +sys.exit(rv) +""" cmd = [ 'python3', - '-m', 'py_compile' + '-c', + script, ] + list(filenames) process = subprocess.Popen( cmd,