]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-143309: fix `test_execve_env_concurrent_mutation_with_fspath_posix` buildbot failu...
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sun, 4 Jan 2026 20:44:47 +0000 (21:44 +0100)
committerGitHub <noreply@github.com>
Sun, 4 Jan 2026 20:44:47 +0000 (21:44 +0100)
Lib/test/test_os/test_os.py

index 67ab945101149d767c0943326e0f9161269058bc..82c55c8ba33065f5f5563d17a50922bf83583c70 100644 (file)
@@ -2627,6 +2627,8 @@ class ExecTests(unittest.TestCase):
     # See https://github.com/python/cpython/issues/137934 and the other
     # related issues for the reason why we cannot test this on Windows.
     @unittest.skipIf(os.name == "nt", "POSIX-specific test")
+    @unittest.skipUnless(unix_shell and os.path.exists(unix_shell),
+                        "requires a shell")
     def test_execve_env_concurrent_mutation_with_fspath_posix(self):
         # Prevent crash when mutating environment during parsing.
         # Regression test for https://github.com/python/cpython/issues/143309.
@@ -2648,14 +2650,17 @@ class ExecTests(unittest.TestCase):
             def keys(self): return KEYS
             def values(self): return VALUES
 
-        args = [sys.executable, '-c', "print({message!r})"]
+        args = [{unix_shell!r}, '-c', 'echo \"{message!s}\"']
         os.execve(args[0], args, MyEnv())
-        """.format(message=message)
+        """.format(unix_shell=unix_shell, message=message)
 
-        # Use '__cleanenv' to signal to assert_python_ok() not
-        # to do a copy of os.environ on its own.
-        rc, out, _ = assert_python_ok('-c', code, __cleanenv=True)
-        self.assertEqual(rc, 0)
+        # Make sure to forward "LD_*" variables so that assert_python_ok()
+        # can run correctly.
+        minimal = {k: v for k, v in os.environ.items() if k.startswith("LD_")}
+        with os_helper.EnvironmentVarGuard() as env:
+            env.clear()
+            env.update(minimal)
+            _, out, _ = assert_python_ok('-c', code, **env)
         self.assertIn(bytes(message, "ascii"), out)
 
     @unittest.skipUnless(sys.platform == "win32", "Win32-specific test")