Skip to content

Commit 2a1e48f

Browse files
author
don012rac3
committed
gh-157006: Clear PYTHONSTARTUP and other PYTHON* env vars in test_embed
run_embedded_interpreter() now defaults to remove_python_envvars() when no explicit env is provided, preventing PYTHONSTARTUP (e.g., set by VS Code shell integration) from leaking into the embedded interpreter and causing test failures. Also fix test_init_run_main_startup_exitcode to use remove_python_envvars() instead of dict(os.environ) as the base environment.
1 parent 7a91841 commit 2a1e48f

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

Lib/test/test_embed.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ def run_embedded_interpreter(self, *args, env=None,
137137
"""Runs a test in the embedded interpreter"""
138138
cmd = [self.test_exe]
139139
cmd.extend(args)
140+
if env is None:
141+
env = remove_python_envvars()
140142
if env is not None and MS_WINDOWS:
141143
# Windows requires at least the SYSTEMROOT environment variable to
142144
# start Python.
@@ -628,7 +630,7 @@ def test_init_run_main_startup_exitcode(self):
628630
with open(filename, 'x') as fp:
629631
fp.write(CODE_EXITCODE_123)
630632

631-
env = dict(os.environ)
633+
env = remove_python_envvars()
632634
env['PYTHONSTARTUP'] = filename
633635
self.check_program_exitcode("test_init_run_main_interactive_exitcode",
634636
env=env,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix ``test.test_embed`` to clear ``PYTHON*`` environment variables (including
2+
``PYTHONSTARTUP``) before running embedded interpreter tests, preventing failures
3+
when the test runner's environment has these variables set (e.g., by VS Code's
4+
shell integration).

0 commit comments

Comments
 (0)