Skip to content

New test_site tests fail with -s interpreter flag #140170

@itamaro

Description

@itamaro

Bug report

Bug description:

When running the test suite with the option to not add user site directory to sys.path (-s interpreter flag, or PYTHONNOUSERSITE=x env var), there are 5 new test failures from recently added test_site tests.

./python.exe -s -m test test_site -v
# or
PYTHONNOUSERSITE=x ./python.exe -m test test_site -v

Failing tests:

======================================================================
FAIL: test_base_arg (test.test_site.CommandLineTests.test_base_arg)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/itamaro/work/cpython/Lib/test/test_site.py", line 898, in test_base_arg
    self.assertEqual(return_code, excepted_return_code)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 1

======================================================================
FAIL: test_both_args (test.test_site.CommandLineTests.test_both_args)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/itamaro/work/cpython/Lib/test/test_site.py", line 915, in test_both_args
    self.assertEqual(return_code, excepted_return_code)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 1

======================================================================
FAIL: test_no_args (test.test_site.CommandLineTests.test_no_args)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/itamaro/work/cpython/Lib/test/test_site.py", line 884, in test_no_args
    self.assertEqual(lines[-1], f"ENABLE_USER_SITE: {site.ENABLE_USER_SITE}")
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'ENABLE_USER_SITE: True' != 'ENABLE_USER_SITE: False'
- ENABLE_USER_SITE: True
?                   ^^^
+ ENABLE_USER_SITE: False
?                   ^^^^


======================================================================
FAIL: test_site_arg (test.test_site.CommandLineTests.test_site_arg)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/itamaro/work/cpython/Lib/test/test_site.py", line 906, in test_site_arg
    self.assertEqual(return_code, excepted_return_code)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 1

======================================================================
FAIL: test_underpth_no_user_site (test.test_site._pthFileTests.test_underpth_no_user_site)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/itamaro/work/cpython/Lib/test/test_site.py", line 814, in test_underpth_no_user_site
    self.assertEqual(p.returncode, 0, "sys.flags.no_user_site was 0")
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 1 != 0 : sys.flags.no_user_site was 0

These tests pass without the -s flag (or env var).

The failing tests seem to be testing specifically behavior around user site, so maybe that's expected? Should these tests skip if the "no user site" option is enabled for the test runner?

CPython versions tested on:

3.14, 3.15, CPython main branch

Operating systems tested on:

macOS, Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions