Skip to content

gh-128779: Fix system site-packages test inside a virtual environment - #160133

Merged
ambv merged 1 commit into
python:mainfrom
ambv:gh-128779-system-site-packages-base-prefix
Oct 21, 2026
Merged

ambv merged 1 commit into
python:mainfrom
ambv:gh-128779-system-site-packages-base-prefix

Conversation

@ambv

@ambv ambv commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fix the test_site.ImportSideEffectTests.test_system_site_packages regression introduced by #129462, which is failing the Hypothesis tests on Ubuntu job on unrelated PRs, including #101318.

The job runs the test suite inside hypovenv. Selecting the system install scheme with _get_preferred_schemes() does not reset its expansion variables: base and platbase still describe that outer virtual environment. The test therefore expects the outer environment's site-packages in a nested virtual environment created with system_site_packages=True, although that environment uses the base interpreter's system site-packages.

Expand the existing system scheme with sys.base_prefix and sys.base_exec_prefix. The existing assertions and the check for absent system site-packages directories remain in place.

Failure log: https://github.com/python/cpython/actions/runs/39679725959/job/119499178669

Verification

On macOS ARM64:

  • Reproduced the original assertion failure inside a virtual environment created from a fresh CPython 3.16 development build, without installing Hypothesis.
  • buildpy completed successfully.
  • testpy test_site passed: 98 tests run, 5 skipped.
  • PYTHONBINARY=<venv>/bin/python testpy test_site passed: 98 tests run, 8 skipped.
  • The fixed target test passed directly and inside a virtual environment on installed Python 3.15, exercising both the exclusion and inclusion assertions with real system site-packages directories.
  • git diff --check passed.

This changes only a test, so no NEWS entry is needed. AI assistance was used to investigate and prepare the change.

…onment

Use the base interpreter prefixes when expanding the system install scheme so nested virtual environments are compared with the base interpreter site-packages rather than the outer virtual environment.

Co-authored-by: Muse Code (Meta Muse Spark)
@ambv
ambv requested review from FFY00 and warsaw as code owners October 21, 2026 22:28
@ambv ambv added the skip news label Oct 21, 2026
@bedevere-app bedevere-app Bot added awaiting core review tests Tests in the Lib/test dir labels Oct 21, 2026
@ambv
ambv merged commit 876b1a5 into python:main Oct 21, 2026
56 checks passed
@ambv
ambv deleted the gh-128779-system-site-packages-base-prefix branch October 21, 2026 23:36
Comment thread Lib/test/test_site.py
))
""")

# Use _get_preferred_schemes to find the system scheme, in case we are in a virtual environment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why revert _get_preferred_schemes instead of just specifying prefix/exec_prefix?

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

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants