Skip to content

gh-157006: Clear PYTHONSTARTUP and other PYTHON* env vars in test_embed - #157008

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

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

Conversation

@ghost

@ghost ghost commented Sep 5, 2026

Copy link
Copy Markdown

When PYTHONSTARTUP (or other PYTHON* env vars) is set in the
test runner's environment — for example, by VS Code's shell integration —
test_embed fails because the embedded interpreter runs the startup
script and produces unexpected output (e.g., "Ctrl click to launch VS
Code Native REPL" before the expected "ok! Py_RunMain() returned 123").

  • run_embedded_interpreter() now defaults to
    remove_python_envvars() when no explicit env is provided
  • test_init_run_main_startup_exitcode now uses
    remove_python_envvars() as the base environment instead of
    dict(os.environ)

Closes #157006

Note: AI tools were used as an aid in developing this change.

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.
@python-cla-bot

python-cla-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Sep 5, 2026
@cmaloney

cmaloney commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

@cmaloney cmaloney closed this Sep 5, 2026
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

1 participant