Skip to content

Preserve isolated sys.path on Python 3.10 - #2211

Merged
nedbat merged 3 commits into
coveragepy:mainfrom
itscloud0:fix-2103-isolated-syspath
Jul 2, 2026
Merged

nedbat merged 3 commits into
coveragepy:mainfrom
itscloud0:fix-2103-isolated-syspath

Conversation

@itscloud0

@itscloud0 itscloud0 commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • preserve isolated-mode sys.path handling in PyRunner.prepare() even on Python versions without sys.flags.safe_path
  • add a process-level regression that compares python -I run_me.py with python -Im coverage run run_me.py

Problem

Fixes #2103.

On Python 3.10, python -Im coverage run poc.py was re-inserting the working directory at sys.path[0], unlike plain python -I poc.py. That also displaced the interpreter's normal isolated-mode zip entry.

Solution

Honor sys.flags.isolated alongside sys.flags.safe_path so isolated-mode runs keep the same path layout that plain Python uses.

@nedbat

nedbat commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

Thanks for all the pull requests. Do you do Discord? I'd like to talk to you: #coverage-py channel.

About this pull request: this seems to only be needed on 3.10, which is going out of support in October. Can we mark this code so that it can be removed then?

In general: what can I do in the coverage repo so that the LLMs will learn the right way to run tests? All of these pull requests have long bullet lists of elaborate commands when tox -e py310 will do.

@itscloud0
itscloud0 marked this pull request as ready for review June 29, 2026 15:54
@nedbat
nedbat merged commit 6f9fa1e into coveragepy:main Jul 2, 2026
42 checks passed
@nedbat

nedbat commented Jul 2, 2026

Copy link
Copy Markdown
Member

This is now released as part of coverage 7.15.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

coverage run in isolated mode does not preserve sys.path correctly Python 3.10

2 participants