diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py index c08eb7cf261568..4ac6b23b7120fc 100644 --- a/Lib/test/test_asyncio/test_subprocess.py +++ b/Lib/test/test_asyncio/test_subprocess.py @@ -1,4 +1,5 @@ import os +import shlex import signal import sys import textwrap @@ -770,9 +771,7 @@ async def check_stdout_output(self, coro, output): def test_create_subprocess_env_shell(self) -> None: async def main() -> None: - executable = sys.executable - if sys.platform == "win32": - executable = f'"{executable}"' + executable = f'"{sys.executable}"' if sys.platform == "win32" else shlex.quote(sys.executable) cmd = f'''{executable} -c "import os, sys; sys.stdout.write(os.getenv('FOO'))"''' env = os.environ.copy() env["FOO"] = "bar" diff --git a/Misc/NEWS.d/next/Tests/2026-05-23-02-42-45.gh-issue-150244.J9yP1-.rst b/Misc/NEWS.d/next/Tests/2026-05-23-02-42-45.gh-issue-150244.J9yP1-.rst new file mode 100644 index 00000000000000..0cfdf176a9ba84 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2026-05-23-02-42-45.gh-issue-150244.J9yP1-.rst @@ -0,0 +1 @@ +Fix ``test_create_subprocess_env_shell`` to properly quote the executable path on both Win32 and UNIX-like systems to properly handle spaces in the path.