Skip to content

AttributeError __spec__ on Python 3.11 #273

Closed
@pawamoy

Description

@pawamoy

Running pytest on Python 3.11:

% python3.11 -m pytest -c config/pytest.ini -n auto tests
Traceback (most recent call last):
  File "/home/pawamoy/.cache/pdm/packages/py-1.10.0-py2.py3-none-any/lib/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/pawamoy/.basher-packages/pyenv/pyenv/versions/3.11-dev/lib/python3.11/runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pawamoy/.basher-packages/pyenv/pyenv/versions/3.11-dev/lib/python3.11/runpy.py", line 146, in _get_module_details
    return _get_module_details(pkg_main_name, error)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pawamoy/.basher-packages/pyenv/pyenv/versions/3.11-dev/lib/python3.11/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
    ^^^^^^^^^^^^^^^^^^^^
  File "/home/pawamoy/.cache/pdm/packages/pytest-6.2.5-py3-none-any/lib/pytest/__init__.py", line 5, in <module>
    from _pytest.assertion import register_assert_rewrite
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pawamoy/.cache/pdm/packages/pytest-6.2.5-py3-none-any/lib/_pytest/assertion/__init__.py", line 9, in <module>
    from _pytest.assertion import rewrite
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pawamoy/.cache/pdm/packages/pytest-6.2.5-py3-none-any/lib/_pytest/assertion/rewrite.py", line 34, in <module>
    from _pytest.assertion import util
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pawamoy/.cache/pdm/packages/pytest-6.2.5-py3-none-any/lib/_pytest/assertion/util.py", line 13, in <module>
    import _pytest._code
    ^^^^^^^^^^^^^^^^^^^^
  File "/home/pawamoy/.cache/pdm/packages/pytest-6.2.5-py3-none-any/lib/_pytest/_code/__init__.py", line 2, in <module>
    from .code import Code
    ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pawamoy/.cache/pdm/packages/pytest-6.2.5-py3-none-any/lib/_pytest/_code/code.py", line 54, in <module>
    class Code:
    ^^^^^^^^^^^
  File "/home/pawamoy/.cache/pdm/packages/pytest-6.2.5-py3-none-any/lib/_pytest/_code/code.py", line 81, in Code
    def path(self) -> Union[py.path.local, str]:
                            ^^^^^^^^^^^^^
  File "/home/pawamoy/.cache/pdm/packages/py-1.10.0-py2.py3-none-any/lib/py/_vendored_packages/apipkg/__init__.py", line 152, in __makeattr
    result = importobj(modpath, attrname)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pawamoy/.cache/pdm/packages/py-1.10.0-py2.py3-none-any/lib/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/pawamoy/.cache/pdm/packages/py-1.10.0-py2.py3-none-any/lib/py/_vendored_packages/apipkg/__init__.py", line 150, in __makeattr
    raise AttributeError(name)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: __spec__

Note: I'm using PDM which uses .pth files in __pypackages__ that point to actual installed packages in ~/.cache/pdm/packages (it allows dedup of packages across projects, saving space and installation time). Not sure this has to do with the issue, but I hear py/apipkg do some black magic on themselves, so this might conflict. It works well on other Python versions though (3.8, 3.9 and 3.10).

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