Skip to content

GH-128779: add test for venv --system-site-packages#129462

Open
FFY00 wants to merge 2 commits into
python:mainfrom
FFY00:gh-128779-test
Open

GH-128779: add test for venv --system-site-packages#129462
FFY00 wants to merge 2 commits into
python:mainfrom
FFY00:gh-128779-test

Conversation

@FFY00
Copy link
Copy Markdown
Member

@FFY00 FFY00 commented Jan 30, 2025

Signed-off-by: Filipe Laíns <lains@riseup.net>
Comment thread Lib/test/test_site.py Outdated
vstinner
vstinner previously approved these changes Jan 30, 2025
Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@vstinner
Copy link
Copy Markdown
Member

Oh, the test fails on macOS:

FAIL: test_system_site_packages (test.test_site.ImportSideEffectTests.test_system_site_packages)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/runner/work/cpython/cpython/Lib/test/test_site.py", line 604, in test_system_site_packages
    assert system_paths['purelib'] in sys_path, sys_path
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: ['', '/opt/python-dev/lib/python314.zip', '/Users/runner/work/cpython/cpython/Lib', '/Users/runner/work/cpython/cpython/build/lib.macosx-10.15-x86_64-3.14', '/var/folders/db/x5_t5x655c9_rftmy0wp2t2w0000gn/T/test_python_gtmi9q2i/test.test_site.ImportSideEffectTests.test_system_site_packages-venv-e7dft2vv/lib/python3.14/site-packages', '/Users/runner/.local/lib/python3.14/site-packages']

And Ubuntu (ARM):

FAIL: test_system_site_packages (test.test_site.ImportSideEffectTests.test_system_site_packages)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/test/test_site.py", line 604, in test_system_site_packages
    assert system_paths['purelib'] in sys_path, sys_path
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: ['', '/usr/local/lib/python314.zip', '/home/runner/work/cpython/cpython-ro-srcdir/Lib', '/home/runner/work/cpython/cpython-builddir/build/lib.linux-aarch64-3.14', '/tmp/test_python_i18th5xw/test.test_site.ImportSideEffectTests.test_system_site_packages-venv-gxaqwl9t/lib/python3.14/site-packages', '/home/runner/.local/lib/python3.14/site-packages']

I applied my suggestion to debug this issue.

@vstinner
Copy link
Copy Markdown
Member

Error using assertIn() and assertNotIn().

macOS (I reformatted the error to make it more readable):

FAIL: test_system_site_packages (test.test_site.ImportSideEffectTests.test_system_site_packages)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/admin/actions-runner/_work/cpython/cpython/Lib/test/test_site.py", line 604, in test_system_site_packages
    self.assertIn(system_paths['purelib'], sys_path)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '/opt/python-dev/lib/python3.14/site-packages' not found in
['',
 '/opt/python-dev/lib/python314.zip',
 '/Users/admin/actions-runner/_work/cpython/cpython/Lib',
 '/Users/admin/actions-runner/_work/cpython/cpython/build/lib.macosx-10.15-arm64-3.14',
 '/var/folders/xf/_tm0f94d66n8kr12tqwrylrr0000gn/T/test_python_txbd6rj8/test.test_site.ImportSideEffectTests.test_system_site_packages-venv-0o61kyua/lib/python3.14/site-packages',
 '/Users/admin/.local/lib/python3.14/site-packages']

Ubuntu (ARM, output also reformatted):

FAIL: test_system_site_packages (test.test_site.ImportSideEffectTests.test_system_site_packages)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/test/test_site.py", line 604, in test_system_site_packages
    self.assertIn(system_paths['purelib'], sys_path)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '/usr/local/lib/python3.14/site-packages' not found in
['',
 '/usr/local/lib/python314.zip',
 '/home/runner/work/cpython/cpython-ro-srcdir/Lib',
 '/home/runner/work/cpython/cpython-builddir/build/lib.linux-aarch64-3.14',
 '/tmp/test_python_9rfle_5u/test.test_site.ImportSideEffectTests.test_system_site_packages-venv-cpa6g3tp/lib/python3.14/site-packages',
 '/home/runner/.local/lib/python3.14/site-packages']

@vstinner vstinner dismissed their stale review January 30, 2025 10:17

I remove my approval since tests fail.

@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 21, 2026
@vstinner
Copy link
Copy Markdown
Member

Are you still working on this PR? If not, I would suggest closing it.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label May 14, 2026
@gaborbernat
Copy link
Copy Markdown
Contributor

Thanks for backfilling regression coverage for gh-128779. Two issues.

It's conflicting and needs a rebase.

The system_site_packages=True half fails on a non-installed/in-tree build, which is how the test suite usually runs. site.py only adds site directories that exist on disk (addsitedir guards on os.path.isdir), but the test asserts the nominal sysconfig.get_paths('posix_prefix')['purelib'] string is in sys.path. On an in-tree build sys.base_prefix is the configure prefix and that …/site-packages directory doesn't exist, so it's never added and the assertion fails. The =False half (assertNotIn) is robust.

For the =True half, assert on observable behavior rather than a path string: drop a marker module into the base purelib (creating the dir) and check it imports with --system-site-packages and not without, or skip when the system site dir is absent. That matches how virtualenv tests this — a real importable package, not a path string.

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

Labels

awaiting review skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants