[Python-checkins] gh-92886: Fix tests that fail when running with optimizations (`-O`) in `test_py_compile.py` (GH-93235)

iritkatriel webhook-mailer at python.org
Wed Oct 19 06:05:17 EDT 2022


https://github.com/python/cpython/commit/602ea40d8936812367db2ffed5226ca25a607f46
commit: 602ea40d8936812367db2ffed5226ca25a607f46
branch: main
author: Jack Hindmarch <1750152+jackh-ncl at users.noreply.github.com>
committer: iritkatriel <1055913+iritkatriel at users.noreply.github.com>
date: 2022-10-19T11:05:08+01:00
summary:

gh-92886: Fix tests that fail when running with optimizations (`-O`) in `test_py_compile.py` (GH-93235)

files:
A Misc/NEWS.d/next/Tests/2022-05-25-22-53-30.gh-issue-92886.mIfdtz.rst
M Lib/test/test_py_compile.py

diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py
index a4a52b180dbb..5e0a44ad9691 100644
--- a/Lib/test/test_py_compile.py
+++ b/Lib/test/test_py_compile.py
@@ -235,11 +235,12 @@ def pycompilecmd(self, *args, **kwargs):
         # assert_python_* helpers don't return proc object. We'll just use
         # subprocess.run() instead of spawn_python() and its friends to test
         # stdin support of the CLI.
+        opts = '-m' if __debug__ else '-Om'
         if args and args[0] == '-' and 'input' in kwargs:
-            return subprocess.run([sys.executable, '-m', 'py_compile', '-'],
+            return subprocess.run([sys.executable, opts, 'py_compile', '-'],
                                   input=kwargs['input'].encode(),
                                   capture_output=True)
-        return script_helper.assert_python_ok('-m', 'py_compile', *args, **kwargs)
+        return script_helper.assert_python_ok(opts, 'py_compile', *args, **kwargs)
 
     def pycompilecmd_failure(self, *args):
         return script_helper.assert_python_failure('-m', 'py_compile', *args)
diff --git a/Misc/NEWS.d/next/Tests/2022-05-25-22-53-30.gh-issue-92886.mIfdtz.rst b/Misc/NEWS.d/next/Tests/2022-05-25-22-53-30.gh-issue-92886.mIfdtz.rst
new file mode 100644
index 000000000000..014e9e614cca
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2022-05-25-22-53-30.gh-issue-92886.mIfdtz.rst
@@ -0,0 +1 @@
+Fixing tests that fail when running with optimizations (``-O``) in ``test_py_compile.py``



More information about the Python-checkins mailing list