Skip to content

Commit d0e9f44

Browse files
[3.14] gh-143309: fix test_execve_env_concurrent_mutation_with_fspath_posix buildbot failure (GH-143415) (#143419)
gh-143309: fix `test_execve_env_concurrent_mutation_with_fspath_posix` buildbot failure (GH-143415) (cherry picked from commit c99f766) Co-authored-by: Bénédikt Tran <[email protected]>
1 parent 623dbaf commit d0e9f44

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Lib/test/test_os.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,6 +2420,8 @@ def test_execve_invalid_env(self):
24202420
# See https://github.com/python/cpython/issues/137934 and the other
24212421
# related issues for the reason why we cannot test this on Windows.
24222422
@unittest.skipIf(os.name == "nt", "POSIX-specific test")
2423+
@unittest.skipUnless(unix_shell and os.path.exists(unix_shell),
2424+
"requires a shell")
24232425
def test_execve_env_concurrent_mutation_with_fspath_posix(self):
24242426
# Prevent crash when mutating environment during parsing.
24252427
# Regression test for https://github.com/python/cpython/issues/143309.
@@ -2441,14 +2443,17 @@ def __len__(self): return 1
24412443
def keys(self): return KEYS
24422444
def values(self): return VALUES
24432445
2444-
args = [sys.executable, '-c', "print({message!r})"]
2446+
args = [{unix_shell!r}, '-c', 'echo \"{message!s}\"']
24452447
os.execve(args[0], args, MyEnv())
2446-
""".format(message=message)
2448+
""".format(unix_shell=unix_shell, message=message)
24472449

2448-
# Use '__cleanenv' to signal to assert_python_ok() not
2449-
# to do a copy of os.environ on its own.
2450-
rc, out, _ = assert_python_ok('-c', code, __cleanenv=True)
2451-
self.assertEqual(rc, 0)
2450+
# Make sure to forward "LD_*" variables so that assert_python_ok()
2451+
# can run correctly.
2452+
minimal = {k: v for k, v in os.environ.items() if k.startswith("LD_")}
2453+
with os_helper.EnvironmentVarGuard() as env:
2454+
env.clear()
2455+
env.update(minimal)
2456+
_, out, _ = assert_python_ok('-c', code, **env)
24522457
self.assertIn(bytes(message, "ascii"), out)
24532458

24542459
@unittest.skipUnless(sys.platform == "win32", "Win32-specific test")

0 commit comments

Comments
 (0)