]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-92886: Fix tests that fail when running with optimizations (`-O`) in `test_py_comp...
authorJack Hindmarch <1750152+jackh-ncl@users.noreply.github.com>
Wed, 19 Oct 2022 10:05:08 +0000 (11:05 +0100)
committerGitHub <noreply@github.com>
Wed, 19 Oct 2022 10:05:08 +0000 (11:05 +0100)
Lib/test/test_py_compile.py
Misc/NEWS.d/next/Tests/2022-05-25-22-53-30.gh-issue-92886.mIfdtz.rst [new file with mode: 0644]

index a4a52b180dbb550b075965c54f3378c6378d89c9..5e0a44ad9691ec30b270b91827a8cbe244320989 100644 (file)
@@ -235,11 +235,12 @@ class PyCompileCLITestCase(unittest.TestCase):
         # 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 (file)
index 0000000..014e9e6
--- /dev/null
@@ -0,0 +1 @@
+Fixing tests that fail when running with optimizations (``-O``) in ``test_py_compile.py``