diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 1ff600e30bf4cb..ada9f4e2992180 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -137,6 +137,8 @@ def run_embedded_interpreter(self, *args, env=None, """Runs a test in the embedded interpreter""" cmd = [self.test_exe] cmd.extend(args) + if env is None: + env = remove_python_envvars() if env is not None and MS_WINDOWS: # Windows requires at least the SYSTEMROOT environment variable to # start Python. @@ -628,7 +630,7 @@ def test_init_run_main_startup_exitcode(self): with open(filename, 'x') as fp: fp.write(CODE_EXITCODE_123) - env = dict(os.environ) + env = remove_python_envvars() env['PYTHONSTARTUP'] = filename self.check_program_exitcode("test_init_run_main_interactive_exitcode", env=env, diff --git a/Misc/NEWS.d/next/Tests/2026-09-06-12-00-00.gh-issue-157006.Xk9mPq.rst b/Misc/NEWS.d/next/Tests/2026-09-06-12-00-00.gh-issue-157006.Xk9mPq.rst new file mode 100644 index 00000000000000..7e6b3db296dc41 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2026-09-06-12-00-00.gh-issue-157006.Xk9mPq.rst @@ -0,0 +1,4 @@ +Fix ``test.test_embed`` to clear ``PYTHON*`` environment variables (including +``PYTHONSTARTUP``) before running embedded interpreter tests, preventing failures +when the test runner's environment has these variables set (e.g., by VS Code's +shell integration).