首页 > 解决方案 > ImportError:使用 pytest 进行测试时无法导入名称“transfer_markers”

问题描述

当我通过运行以下命令为我的 python 项目运行测试时:

python setup.py test
(or)
pytest project_name

我收到以下错误:

.../project_name/.eggs/pytest_asyncio-0.9.0-py3.6.egg/pytest_asyncio/plugin.py", line 8, in <module>
from _pytest.python import transfer_markers

ImportError: cannot import name 'transfer_markers'

标签: pythonpytest

解决方案


当我在网上查到它时,几乎没有任何地方提到那个特定的错误消息。类似的事情发生在我身上好几次了,以前工作的代码刚刚中断,这通常是因为有一个重要包的新版本。

我查看了pytest release history,它看起来像是pytest==4.1.0几个小时前发布的(截至本文为止)。

pytest==4.0.2解决方案是通过运行以下命令恢复到 pytest 的最后一个稳定版本:

pip install pytest==4.0.2

测试现在正在运行。


推荐阅读