pytest-dev / apipkg

MIT License
55 stars 16 forks source link

fails in Python 3.11 when running pytest from tox #30

Closed davidism closed 3 years ago

davidism commented 3 years ago

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 commented 3 years ago

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

RonnyPfannschmidt commented 3 years ago

@davidism the release is already available

davidism commented 3 years ago

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

CodingTil commented 2 years ago

the release is already available

(and https://github.com/pytest-dev/py/issues/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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Upgrading library py to 1.11.0  solved the problem for me.

sparrowt commented 1 year ago

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 https://github.com/pytest-dev/pytest/issues/9181#issuecomment-1513234948