Skip to content

Commit 602ea40

Browse files
authored
gh-92886: Fix tests that fail when running with optimizations (-O) in test_py_compile.py (GH-93235)
1 parent 9be05df commit 602ea40

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Lib/test/test_py_compile.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,12 @@ def pycompilecmd(self, *args, **kwargs):
235235
# assert_python_* helpers don't return proc object. We'll just use
236236
# subprocess.run() instead of spawn_python() and its friends to test
237237
# stdin support of the CLI.
238+
opts = '-m' if __debug__ else '-Om'
238239
if args and args[0] == '-' and 'input' in kwargs:
239-
return subprocess.run([sys.executable, '-m', 'py_compile', '-'],
240+
return subprocess.run([sys.executable, opts, 'py_compile', '-'],
240241
input=kwargs['input'].encode(),
241242
capture_output=True)
242-
return script_helper.assert_python_ok('-m', 'py_compile', *args, **kwargs)
243+
return script_helper.assert_python_ok(opts, 'py_compile', *args, **kwargs)
243244

244245
def pycompilecmd_failure(self, *args):
245246
return script_helper.assert_python_failure('-m', 'py_compile', *args)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixing tests that fail when running with optimizations (``-O``) in ``test_py_compile.py``

0 commit comments

Comments
 (0)