GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Virtual environment breaks `test_sysconfig` and `test_venv` tests on macOS · Issue #103224 · python/cpython

Virtual environment breaks test_sysconfig and test_venv tests on macOS #103224

New issue
Copy link
New issue
Copy link
Open
Open
Virtual environment breaks test_sysconfig and test_venv tests on macOS#103224
Copy link
Labels
OS-mactestsTests in the Lib/test dirTests in the Lib/test dirtopic-sysconfigtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@artemmukhin
artemmukhin
opened on Apr 3, 2023
Issue body actions

Bug report

  1. Build CPython on macOS
  2. Activate a virtual environment as described in https://devguide.python.org/testing/coverage/#install-coverage
  3. Run python -m test

Results in:

== Tests result: FAILURE ==

2 tests failed:
    test_sysconfig test_venv

$ python -m test test_venv --verbose
...
AssertionError: Lists differ

First differing element 0:
'/.../bin/python.exe'
'/.../bin/python'

TODO

  • Fix test_sysconfig gh-103224: Resolve paths properly in test_sysconfig #103292
  • Fix test_venv GH-103224: Use the realpath of the Python executable in test_venv #103243

Your environment

  • CPython versions tested on: main
  • Operating system and architecture: macOS 13.2.1

Linked PRs

  • GH-103224: Use the realpath of the Python executable in test_venv #103243
  • gh-103224: Resolve paths properly in test_sysconfig #103292
  • Revert "gh-103224: Use the realpath of the Python executable in test_venv (GH-103243)" #108667
  • [3.12] gh-103224: Resolve paths properly in test_sysconfig (GH-103292) #115100
  • [3.11] gh-103224: Resolve paths properly in test_sysconfig (GH-103292) #115101

Activity

Next
  1. artemmukhin
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Apr 3, 2023
  2. dtrodrigues commented on Apr 4, 2023

    @dtrodrigues
    dtrodrigues
    on Apr 4, 2023
    Contributor
    More actions

    What if you do python.exe -m test or python.exe -m test test_venv --verbose?

  3. arhadthedev
    added
    testsTests in the Lib/test dirTests in the Lib/test dir
    OS-mac
    on Apr 4, 2023
  4. artemmukhin
    added a commit that references this issue on Apr 4, 2023

    pythonGH-103224: Use the realpath of the Python executable in `test_v…

    67576f5
  5. artemmukhin commented on Apr 4, 2023

    @artemmukhin
    artemmukhin
    on Apr 4, 2023
    ContributorAuthor
    More actions

    @dtrodrigues Both python.exe -m test and python.exe -m test test_venv --verbose finish without failures. test_sysconfig passes only when I run ./python.exe and not the symlink python.exe.

    I have opened a PR regarding test_venv.

  6. artemmukhin commented on Apr 4, 2023

    @artemmukhin
    artemmukhin
    on Apr 4, 2023
    ContributorAuthor
    More actions

    Regarding test_sysconfig, I found out that replacing sys.prefix with sys.base_prefix makes test_sysconfig passes with both ./python.exe and python.exe symlink.

    Although I'm not entirely sure if this is the correct way to fix the test. So before opening the next PR regarding test_sysconfig, I would like to confirm this is the appropriate solution.

    @hroncok Could you please take a look if you have a chance? Here is a patch:

    diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
    index b6dbf3d52c..a95e7f4367 100644
    --- a/Lib/test/test_sysconfig.py
    +++ b/Lib/test/test_sysconfig.py
    @@ -151,7 +151,7 @@ def test_posix_venv_scheme(self):
    
             # Resolve the paths in prefix
             binpath = os.path.join(sys.prefix, binpath)
    -        incpath = os.path.join(sys.prefix, incpath)
    +        incpath = os.path.join(sys.base_prefix, incpath)
             libpath = os.path.join(sys.prefix, libpath)
    
             self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='posix_venv'))
    @@ -171,7 +171,7 @@ def test_nt_venv_scheme(self):
    
             # Resolve the paths in prefix
             binpath = os.path.join(sys.prefix, binpath)
    -        incpath = os.path.join(sys.prefix, incpath)
    +        incpath = os.path.join(sys.base_prefix, incpath)
             libpath = os.path.join(sys.prefix, libpath)
    
             self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='nt_venv'))
  7. hroncok commented on Apr 4, 2023

    @hroncok
    hroncok
    on Apr 4, 2023
    Contributor
    More actions

    Will do! It has been a while since I wrote that, but I'll try to figure it out.

    Reacted by Artem Mukhin
  8. hroncok commented on Apr 4, 2023

    @hroncok
    hroncok
    on Apr 4, 2023
    Contributor
    More actions

    The include path is indeed defined via installed_base and the default for insatlled_base is sys.base_prefix, so the diff makes the test pass but arguably makes the test more fragile for potential future posix_venv changes.

    I suggest instead of "Resolve the paths in prefix" we resolve the paths in "venv/" and then we set vars to a dict similar to the one in

    cpython/Lib/venv/__init__.py

    Lines 97 to 102 in f513d5c

    vars = {
    'base': env_dir,
    'platbase': env_dir,
    'installed_base': env_dir,
    'installed_platbase': env_dir,
    }
    when calling get_path.

    Something like this (untested):

    diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
    index b6dbf3d52cb..1137c2032b9 100644
    --- a/Lib/test/test_sysconfig.py
    +++ b/Lib/test/test_sysconfig.py
    @@ -149,17 +149,21 @@ def test_posix_venv_scheme(self):
                                    'python%d.%d' % sys.version_info[:2],
                                    'site-packages')
     
    -        # Resolve the paths in prefix
    -        binpath = os.path.join(sys.prefix, binpath)
    -        incpath = os.path.join(sys.prefix, incpath)
    -        libpath = os.path.join(sys.prefix, libpath)
    +        # Resolve the paths in an imaginary venv/ directory
    +        binpath = os.path.join('venv', binpath)
    +        incpath = os.path.join('venv', incpath)
    +        libpath = os.path.join('venv', libpath)
     
    -        self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='posix_venv'))
    -        self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='posix_venv'))
    +        # Mimic the venv module, set all bases to the venv directory
    +        bases = ('base', 'platbase', 'installed_base', 'installed_platbase')
    +        vars = {base: 'venv' for base in bases}
    +
    +        self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='posix_venv', vars=vars))
    +        self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='posix_venv', vars=vars))
     
             # The include directory on POSIX isn't exactly the same as before,
             # but it is "within"
    -        sysconfig_includedir = sysconfig.get_path('include', scheme='posix_venv')
    +        sysconfig_includedir = sysconfig.get_path('include', scheme='posix_venv', vars=vars)
             self.assertTrue(sysconfig_includedir.startswith(incpath + os.sep))
     
         def test_nt_venv_scheme(self):
    @@ -169,14 +173,19 @@ def test_nt_venv_scheme(self):
             incpath = 'Include'
             libpath = os.path.join('Lib', 'site-packages')
     
    -        # Resolve the paths in prefix
    -        binpath = os.path.join(sys.prefix, binpath)
    -        incpath = os.path.join(sys.prefix, incpath)
    -        libpath = os.path.join(sys.prefix, libpath)
    +        # Resolve the paths in an imaginary venv\ directory
    +        venv = 'venv'
    +        binpath = os.path.join(venv, binpath)
    +        incpath = os.path.join(venv, incpath)
    +        libpath = os.path.join(venv, libpath)
    +
    +        # Mimic the venv module, set all bases to the venv directory
    +        bases = ('base', 'platbase', 'installed_base', 'installed_platbase')
    +        vars = {base: 'venv' for base in bases}
     
    -        self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='nt_venv'))
    -        self.assertEqual(incpath, sysconfig.get_path('include', scheme='nt_venv'))
    -        self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='nt_venv'))
    +        self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='nt_venv', vars=vars))
    +        self.assertEqual(incpath, sysconfig.get_path('include', scheme='nt_venv', vars=vars))
    +        self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='nt_venv', vars=vars))
     
         def test_venv_scheme(self):
             if sys.platform == 'win32':

    I think that this should have been done initially and my test was buggy.

  9. artemmukhin
    added 2 commits that reference this issue on Apr 5, 2023

    pythonGH-103224: Resolve paths properly in `test_sysconfig` to pass w…

    3080c11

    pythonGH-103224: Resolve paths properly in `test_sysconfig`

    51f0236
  10. artemmukhin commented on Apr 5, 2023

    @artemmukhin
    artemmukhin
    on Apr 5, 2023
    ContributorAuthor
    More actions

    @hroncok Thank you! Your patch fixes the tests for me, so I have opened a PR #103292

  11. vsajip
    added a commit that references this issue on Jun 1, 2023

    gh-103224: Use the realpath of the Python executable in `test_venv` (G…

    85b0b0c
  12. zooba commented on Jun 8, 2023

    @zooba
    zooba
    on Jun 8, 2023
    Member
    More actions

    This change causes tests to break when configured and run through a prefix:

    ./configure --with-openssl=/usr/local/opt/openssl \
                --prefix=$(Py_TargetDir) \
                --enable-shared \
                --enable-universalsdk --with-universal-archs=intel-64
    make -j4 install
    make buildbottest TESTOPTS="-j4 -uall,-cpu --tempdir=$(Py_IntDir)/tests"
    

    macOS Logs:

    Details
    ======================================================================
    ERROR: test_zippath_from_non_installed_posix (test.test_venv.BasicTest.test_zippath_from_non_installed_posix)
    Test that when create venv from non-installed python, the zip path
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/runner/work/1/a/layout/lib/python3.13/test/test_venv.py", line 612, in test_zippath_from_non_installed_posix
        subprocess.check_call(cmd, env=child_env)
      File "/Users/runner/work/1/a/layout/lib/python3.13/subprocess.py", line 408, in check_call
        retcode = call(*popenargs, **kwargs)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/runner/work/1/a/layout/lib/python3.13/subprocess.py", line 389, in call
        with Popen(*popenargs, **kwargs) as p:
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/runner/work/1/a/layout/lib/python3.13/subprocess.py", line 1026, in __init__
        self._execute_child(args, executable, preexec_fn, close_fds,
      File "/Users/runner/work/1/a/layout/lib/python3.13/subprocess.py", line 1950, in _execute_child
        raise child_exception_type(errno_num, err_msg, err_filename)
    FileNotFoundError: [Errno 2] No such file or directory: '/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/test_python_ceck5p2j/tmpv23r1zhj/bin/python3'
    
    ======================================================================
    FAIL: test_upgrade_dependencies (test.test_venv.BasicTest.test_upgrade_dependencies)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/runner/work/1/a/layout/lib/python3.13/test/test_venv.py", line 236, in test_upgrade_dependencies
        builder.upgrade_dependencies(fake_context)
      File "/Users/runner/work/1/a/layout/lib/python3.13/venv/__init__.py", line 459, in upgrade_dependencies
        self._call_new_python(context, '-m', 'pip', 'install', '--upgrade',
      File "/Users/runner/work/1/a/layout/lib/python3.13/venv/__init__.py", line 355, in _call_new_python
        subprocess.check_output(args, **kwargs)
      File "/Users/runner/work/1/a/layout/lib/python3.13/test/test_venv.py", line 222, in pip_cmd_checker
        self.assertEqual(
    AssertionError: Lists differ: ['/va[76 chars]ct/bin/python3', '-m', 'pip', 'install', '--upgrade', 'pip'] != ['/va[76 chars]ct/bin/python3.13', '-m', 'pip', 'install', '--upgrade', 'pip']
    
    First differing element 0:
    '/var[30 chars]sl6xvm0000gn/T/test_python_ceck5p2j/tmp37gcakct/bin/python3'
    '/var[30 chars]sl6xvm0000gn/T/test_python_ceck5p2j/tmp37gcakct/bin/python3.13'
    
    - ['/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/test_python_ceck5p2j/tmp37gcakct/bin/python3',
    + ['/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/test_python_ceck5p2j/tmp37gcakct/bin/python3.13',
    ?                                                                                                +++
    
       '-m',
       'pip',
       'install',
       '--upgrade',
       'pip']
    

    I get the same failure (slightly different paths) on Ubuntu.

    Any other thoughts on how to solve the original issue?

  13. hroncok commented on Jun 8, 2023

    @hroncok
    hroncok
    on Jun 8, 2023
    Contributor
    More actions

    Even with #103292 ?

  14. 3 remaining items

  15. zooba commented on Jun 8, 2023

    @zooba
    zooba
    on Jun 8, 2023
    Member
    More actions

    Well, it doesn't give me any more failures at least.

    I think the problem is that make buildbottest launches through a different symlink after make install than the usual test suite? Or it's doing realpath in a place where venv does not (which is obviously true, because this only started failing when the extra realpath was added, but that doesn't mean that simply reverting is the right fix).

    Clearly we just need to make the test robust enough for both scenarios, as both are legitimate. I'm not sure what the original problem being solved is though, so the best I can do is try to revert the change.

  16. zooba commented on Jul 3, 2023

    @zooba
    zooba
    on Jul 3, 2023
    Member
    More actions

    FWIW, I fixed this for myself by running tests through python3.x rather than through python3.

    I still think we should be able to handle both, but at least it's probably just a test issue.

  17. serhiy-storchaka commented on Aug 30, 2023

    @serhiy-storchaka
    serhiy-storchaka
    on Aug 30, 2023
    Member
    More actions

    #103243 broke some builtbots.
    https://buildbot.python.org/all/#/builders/363/builds/1147/steps/7/logs/stdio
    https://buildbot.python.org/all/#/builders/292/builds/1142/steps/7/logs/stdio
    https://buildbot.python.org/all/#/builders/356/builds/1153/steps/7/logs/stdio
    https://buildbot.python.org/all/#/builders/465/builds/1204/steps/7/logs/stdio

    Details
    ======================================================================
    ERROR: test_zippath_from_non_installed_posix (test.test_venv.BasicTest.test_zippath_from_non_installed_posix)
    Test that when create venv from non-installed python, the zip path
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/buildbot/buildarea/pull_request.cstratak-fedora-stable-x86_64.clang-installed/build/target/lib/python3.13/test/test_venv.py", line 612, in test_zippath_from_non_installed_posix
        subprocess.check_call(cmd, env=child_env)
      File "/home/buildbot/buildarea/pull_request.cstratak-fedora-stable-x86_64.clang-installed/build/target/lib/python3.13/subprocess.py", line 408, in check_call
        retcode = call(*popenargs, **kwargs)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/buildbot/buildarea/pull_request.cstratak-fedora-stable-x86_64.clang-installed/build/target/lib/python3.13/subprocess.py", line 389, in call
        with Popen(*popenargs, **kwargs) as p:
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/buildbot/buildarea/pull_request.cstratak-fedora-stable-x86_64.clang-installed/build/target/lib/python3.13/subprocess.py", line 1026, in __init__
        self._execute_child(args, executable, preexec_fn, close_fds,
      File "/home/buildbot/buildarea/pull_request.cstratak-fedora-stable-x86_64.clang-installed/build/target/lib/python3.13/subprocess.py", line 1950, in _execute_child
        raise child_exception_type(errno_num, err_msg, err_filename)
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmp_6mtreoe/bin/python3'
    ======================================================================
    FAIL: test_upgrade_dependencies (test.test_venv.BasicTest.test_upgrade_dependencies)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/buildbot/buildarea/pull_request.cstratak-fedora-stable-x86_64.clang-installed/build/target/lib/python3.13/test/test_venv.py", line 236, in test_upgrade_dependencies
        builder.upgrade_dependencies(fake_context)
      File "/home/buildbot/buildarea/pull_request.cstratak-fedora-stable-x86_64.clang-installed/build/target/lib/python3.13/venv/__init__.py", line 459, in upgrade_dependencies
        self._call_new_python(context, '-m', 'pip', 'install', '--upgrade',
      File "/home/buildbot/buildarea/pull_request.cstratak-fedora-stable-x86_64.clang-installed/build/target/lib/python3.13/venv/__init__.py", line 355, in _call_new_python
        subprocess.check_output(args, **kwargs)
      File "/home/buildbot/buildarea/pull_request.cstratak-fedora-stable-x86_64.clang-installed/build/target/lib/python3.13/test/test_venv.py", line 222, in pip_cmd_checker
        self.assertEqual(
    AssertionError: Lists differ: ['/tmp/tmp77w4qegx/bin/python3', '-m', 'pip', 'install', '--upgrade', 'pip'] != ['/tmp/tmp77w4qegx/bin/python3.13', '-m', 'pip', 'install', '--upgrade', 'pip']
    First differing element 0:
    '/tmp/tmp77w4qegx/bin/python3'
    '/tmp/tmp77w4qegx/bin/python3.13'
    - ['/tmp/tmp77w4qegx/bin/python3', '-m', 'pip', 'install', '--upgrade', 'pip']
    + ['/tmp/tmp77w4qegx/bin/python3.13', '-m', 'pip', 'install', '--upgrade', 'pip']
    ?                               +++
    ----------------------------------------------------------------------
    

    It can be easily reproduced by creating a symlink to Python executable and running tests via the symlink.

    ln -s python pythonx
    ./pythonx -m test -vuall test_venv
    

    Reverting #103243 fixes this issue. I actually first wrote a fix myself, but it turned out to be equivalent to the reversion of #103243.

  18. serhiy-storchaka
    added a commit that references this issue on Aug 30, 2023

    Revert "pythongh-103224: Use the realpath of the Python executable in…

    236d376
  19. vsajip commented on Aug 30, 2023

    @vsajip
    vsajip
    on Aug 30, 2023
    Member
    More actions

    I've approved the reversion - @artemmukhin perhaps the change needed to be more narrowly applied? If you want to work up a PR we can test with the build-bots first before finalizing it.

  20. serhiy-storchaka commented on Aug 30, 2023

    @serhiy-storchaka
    serhiy-storchaka
    on Aug 30, 2023
    Member
    More actions

    I have no macOS. Can the original issue be reproduced on non-macOS? What exactly the failure report, which lines fail and with what output?

  21. serhiy-storchaka
    added a commit that references this issue on Aug 30, 2023

    Revert "gh-103224: Use the realpath of the Python executable in `test…

    210a5d7
  22. carljm
    added a commit that references this issue on Aug 30, 2023

    Merge branch 'main' into icompexc

    37377e6
  23. FFY00
    added
    topic-sysconfig
    on Oct 24, 2023
  24. serhiy-storchaka
    added a commit that references this issue on Feb 6, 2024

    gh-103224: Resolve paths properly in test_sysconfig (GH-103292)

    71239d5
  25. miss-islington
    added 2 commits that reference this issue on Feb 6, 2024

    pythongh-103224: Resolve paths properly in test_sysconfig (pythonGH-1…

    bce6ca7

    pythongh-103224: Resolve paths properly in test_sysconfig (pythonGH-1…

    763af10
  26. serhiy-storchaka
    added 2 commits that reference this issue on Feb 7, 2024

    [3.12] gh-103224: Resolve paths properly in test_sysconfig (GH-103292) (

    060c3ed

    [3.11] gh-103224: Resolve paths properly in test_sysconfig (GH-103292) (

    3aa4418
  27. fsc-eriker
    added a commit that references this issue on Feb 14, 2024

    pythongh-103224: Resolve paths properly in test_sysconfig (pythonGH-1…

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-mactestsTests in the Lib/test dirTests in the Lib/test dirtopic-sysconfigtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.