Skip to content

exceptiongroup python version import check not compatible with poetry/virtualenv #10956

Description

@sergioisidoro

I'm hitting a problem where using poetry (together with Tox testing matrix) will fail system checks introduced in #10209

Indeed the python version installed system wide is 3.11, but when testing with multiple python versions with Tox and virtual envs, this fails, because the system installed python and environment python is not the same. So

if sys.version_info[:2] < (3, 11):
    from exceptiongroup import BaseExceptionGroup

Will try to import BaseExceptionGroup even though it's being ran in Python <= 3.10

Is it possible to use env markers instead?
https://peps.python.org/pep-0508/#environment-markers

pytest = "^7.3.1"

Related:
python-poetry/poetry#758

Trace:

Traceback (most recent call last):
  File "/home/runner/.cache/pypoetry/virtualenvs/my-package-koh7-DBw-py3.10/bin/py.test", line 5, in <module>
    from pytest import console_main
  File "/home/runner/.cache/pypoetry/virtualenvs/my-package-koh7-DBw-py3.10/lib/python3.10/site-packages/pytest/__init__.py", line 5, in <module>
    from _pytest._code import ExceptionInfo
  File "/home/runner/.cache/pypoetry/virtualenvs/my-package-koh7-DBw-py3.10/lib/python3.10/site-packages/_pytest/_code/__init__.py", line 2, in <module>
    from .code import Code
  File "/home/runner/.cache/pypoetry/virtualenvs/my-package-koh7-DBw-py3.10/lib/python3.10/site-packages/_pytest/_code/code.py", line 60, in <module>
    from exceptiongroup import BaseExceptionGroup
ModuleNotFoundError: No module named 'exceptiongroup'
Error: Process completed with exit code 1.

Activity

  1. RonnyPfannschmidt commented on Apr 29, 2023

    @RonnyPfannschmidt
    Member

    You mean https://github.com/pytest-dev/pytest/blob/main/setup.cfg#L51

    Please verify if this is a poetry issue

    Based on the spec it should work

  2. sergioisidoro commented on Apr 29, 2023

    @sergioisidoro
    Author

    I don't think it's about the line you mention.
    The tests run ok in Py3.11, and fails on all others bellow.
    I'm using github actions actions/setup-python@v4.5.0 to set the python version.

    I will continue to investigate to check if there's anything I missed in the pipepilne.

  3. sergioisidoro commented on Apr 29, 2023

    @sergioisidoro
    Author

    Indeed it does not seem to be a problem with pytest. version_info is correct, even in the CI env

    import sys
    print(sys.version_info)
    print(sys.version_info[:2])
    
    > poetry run python echo_py.py
    --->
    sys.version_info(major=3, minor=10, micro=[11](https://github.com/sergioisidoro/my-package/actions/runs/4838885495/jobs/8623593821?pr=1#step:9:11), releaselevel='final', serial=0)
    (3, 10)
    

    Still no idea what's going on...

  4. RonnyPfannschmidt commented on Apr 29, 2023

    @RonnyPfannschmidt
    Member

    Is the poetry dependency resolver running on the right python version?

  5. JamesHutchison commented on May 17, 2023

    @JamesHutchison

    I encountered this issue. In my case, I started with a Python 3.11 dev container with poetry pegged to the 3.11 version. I opened up the version to 3.10 but forgot to rebuild the poetry lock file. The fix was to run poetry lock and commit the updated lock file.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions