Skip to content

gh-157006: Clear PYTHON* env vars in test_embed - #157009

Closed
ghost wants to merge 1 commit into
mainfrom
unknown repository
Closed

gh-157006: Clear PYTHON* env vars in test_embed#157009
ghost wants to merge 1 commit into
mainfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Sep 5, 2026

Copy link
Copy Markdown

I ran into test_embed failures on my machine because VS Code's shell integration sets PYTHONSTARTUP in the environment. The embedded interpreter would pick it up and run the startup script, so the output had extra text before the expected "ok! Py_RunMain() returned 123".

The fix is straightforward: run_embedded_interpreter() now calls remove_python_envvars() when no explicit env is passed, so PYTHON* variables from the parent process don't leak in. I also updated test_init_run_main_startup_exitcode to use remove_python_envvars() as its base env instead of dict(os.environ), since that test sets its own PYTHONSTARTUP and shouldn't inherit whatever happens to be in the surroundings.

Closes #157006

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.
@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Sep 5, 2026
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_embed may fail if PYTHONSTARTUP set

0 participants