我目前正在尝试将更大的代码库从Python 3.8更新到Python 3.11。我使用pyenv
来管理我的Python版本,使用poetry
来管理我的依赖项:
pyenv local 3.11.3
poetry update
当我运行pytest
时,我立即得到:
python -m pytest -n 1
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1074, in _find_spec
AttributeError: 'VendorAlias' object has no attribute 'find_spec'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/django/utils/module_loading.py", line 58, in autodiscover_modules
import_module("%s.%s" % (app_config.name, module_to_search))
File "/home/martin/.pyenv/versions/3.11.1/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1076, in _find_spec
File "<frozen importlib._bootstrap>", line 1049, in _find_spec_legacy
ImportWarning: VendorAlias.find_spec() not found; falling back to find_module()
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1074, in _find_spec
AttributeError: 'VendorAlias' object has no attribute 'find_spec'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/pytest/__main__.py", line 5, in <module>
raise SystemExit(pytest.console_main())
^^^^^^^^^^^^^^^^^^^^^
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/_pytest/config/__init__.py", line 189, in console_main
code = main()
^^^^^^
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/_pytest/config/__init__.py", line 147, in main
config = _prepareconfig(args, plugins)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/_pytest/config/__init__.py", line 328, in _prepareconfig
config = pluginmanager.hook.pytest_cmdline_parse(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/pluggy/_callers.py", line 55, in _multicall
gen.send(outcome)
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/_pytest/helpconfig.py", line 103, in pytest_cmdline_parse
config: Config = outcome.get_result()
^^^^^^^^^^^^^^^^^^^^
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1067, in pytest_cmdline_parse
self.parse(args)
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1354, in parse
self._preparse(args, addopts=addopts)
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1256, in _preparse
self.hook.pytest_load_initial_conftests(
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/pluggy/_callers.py", line 60, in _multicall
return outcome.get_result()
^^^^^^^^^^^^^^^^^^^^
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/pytest_django/plugin.py", line 353, in pytest_load_initial_conftests
_setup_django()
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/pytest_django/plugin.py", line 236, in _setup_django
django.setup()
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/django/apps/registry.py", line 124, in populate
app_config.ready()
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/django/contrib/admin/apps.py", line 27, in ready
self.module.autodiscover()
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/django/contrib/admin/__init__.py", line 50, in autodiscover
autodiscover_modules("admin", register_to=site)
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/django/utils/module_loading.py", line 70, in autodiscover_modules
if module_has_submodule(app_config.module, module_to_search):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/martin/.cache/pypoetry/virtualenvs/web-backend-4tJQ0X3K-py3.11/lib/python3.11/site-packages/django/utils/module_loading.py", line 85, in module_has_submodule
return importlib_find(full_module_name, package_path) is not None
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib.util>", line 103, in find_spec
File "<frozen importlib._bootstrap>", line 1076, in _find_spec
File "<frozen importlib._bootstrap>", line 1049, in _find_spec_legacy
ImportWarning: VendorAlias.find_spec() not found; falling back to find_module()
我不知道这是从哪里来的
卸载pytest-django
时,至少可以启动pytest
。然而,在一个相关的项目中,一切都工作得很好——包括同一版本的pytest-djanog
。
升级到Python 3.9工作,但升级到3.10(和3.11)失败。
我该如何调查这个问题?
依赖倡导者似乎是原因。我不知道它是如何使pytest失败的——这与Python 2的兼容性有关。
我是通过grep
-ingVendorAlias
的虚拟环境找到它的