Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fails in Python 3.11 when running pytest from tox #30

Closed
davidism opened this issue Nov 5, 2021 · 8 comments
Closed

fails in Python 3.11 when running pytest from tox #30

davidism opened this issue Nov 5, 2021 · 8 comments

Comments

@davidism
Copy link

davidism commented Nov 5, 2021

I wanted to run Jinja's tests against 3.11.0a1. However, I get the following exception from apipkg when pytest is run from tox.
If I create a 3.11 virtualenv manually and run pytest directly, it succeeds.

Traceback (most recent call last):
  File "/home/david/Projects/pallets/jinja/.tox/py311/lib/python3.11/site-packages/py/_vendored_packages/apipkg/__init__.py", line 145, in __makeattr
    modpath, attrname = self.__map__[name]
                        ~~~~~~~~~~~~^^^^^^
KeyError: '__spec__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/david/Projects/pallets/jinja/.tox/py311/bin/pytest", line 5, in <module>
    from pytest import console_main
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/david/Projects/pallets/jinja/.tox/py311/lib/python3.11/site-packages/pytest/__init__.py", line 5, in <module>
    from _pytest.assertion import register_assert_rewrite
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/david/Projects/pallets/jinja/.tox/py311/lib/python3.11/site-packages/_pytest/assertion/__init__.py", line 9, in <module>
    from _pytest.assertion import rewrite
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/david/Projects/pallets/jinja/.tox/py311/lib/python3.11/site-packages/_pytest/assertion/rewrite.py", line 34, in <module>
    from _pytest.assertion import util
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/david/Projects/pallets/jinja/.tox/py311/lib/python3.11/site-packages/_pytest/assertion/util.py", line 13, in <module>
    import _pytest._code
    ^^^^^^^^^^^^^^^^^^^^
  File "/home/david/Projects/pallets/jinja/.tox/py311/lib/python3.11/site-packages/_pytest/_code/__init__.py", line 2, in <module>
    from .code import Code
    ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/david/Projects/pallets/jinja/.tox/py311/lib/python3.11/site-packages/_pytest/_code/code.py", line 54, in <module>
    class Code:
    ^^^^^^^^^^^
  File "/home/david/Projects/pallets/jinja/.tox/py311/lib/python3.11/site-packages/_pytest/_code/code.py", line 81, in Code
    def path(self) -> Union[py.path.local, str]:
                            ^^^^^^^^^^^^^
  File "/home/david/Projects/pallets/jinja/.tox/py311/lib/python3.11/site-packages/py/_vendored_packages/apipkg/__init__.py", line 152, in __makeattr
    result = importobj(modpath, attrname)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/david/Projects/pallets/jinja/.tox/py311/lib/python3.11/site-packages/py/_vendored_packages/apipkg/__init__.py", line 72, in importobj
    module = __import__(modpath, None, None, ['__doc__'])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1044, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
  File "/home/david/Projects/pallets/jinja/.tox/py311/lib/python3.11/site-packages/py/_vendored_packages/apipkg/__init__.py", line 150, in __makeattr
    raise AttributeError(name)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: __spec__
@davidism
Copy link
Author

davidism commented Nov 5, 2021

Looks like pytest-dev/py#273 and pytest-dev/pytest#9181 are the tracking issues, this is already fixed in the next release according to that.

@davidism davidism closed this as completed Nov 5, 2021
@RonnyPfannschmidt
Copy link
Member

@davidism the release is already available

@davidism
Copy link
Author

davidism commented Nov 5, 2021

Yes, I just realized it was released literally right after I did my monthly requirements pin updates. Thanks!

vinitkumar added a commit to vinitkumar/json2xml that referenced this issue Dec 30, 2021
Pytest and Py package are both broken unless a latest version of both
are released. In order to fix this, both of them are upgraded.

The following issue can take to both the issues:
  pytest-dev/apipkg#30

Authored-by: Vinit Kumar <[email protected]>
Signed-off-by: Vinit Kumar <[email protected]>
vinitkumar added a commit to vinitkumar/json2xml that referenced this issue Dec 30, 2021
* feat: be specific with the os version and give python3.11-alpha3 a try

* fix: broken package in python3.11

Pytest and Py package are both broken unless a latest version of both
are released. In order to fix this, both of them are upgraded.

The following issue can take to both the issues:
  pytest-dev/apipkg#30

Authored-by: Vinit Kumar <[email protected]>
Signed-off-by: Vinit Kumar <[email protected]>

* fix: missing comma
@CodingTil
Copy link

the release is already available

(and pytest-dev/py#273)

Where? Idk, I basically have no idea what I am doing, but couldn't find anything in this repo nor in the py repo, nor is there anything new on pypi. All my dependencies are up-to-date.
What do I have to do?

I get the exact same error.

@montykamath
Copy link

the release is already available

what release version of what package or python fixes this problem?

i'm asking, because i also get the exact same error with python 3.11.2 and pytest 7.2.1.

i've also tried including apipkg==3.0.1 in my requirements.txt and it made no difference

@davidism
Copy link
Author

Open a new issue with a minimal reproducible example if you're having a problem. Commenting "this still happens" with no additional details on a two year old closed issue isn't helpful.

@sorrat
Copy link

sorrat commented Mar 10, 2023

Upgrading library py to 1.11.0  solved the problem for me.

@sparrowt
Copy link

i also get the exact same error with python 3.11.2 and pytest 7.2.1.

You may have an older version of py left behind in your python environment (because pytest used to depend on it) see this comment for more details pytest-dev/pytest#9181 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants