简体   繁体   中英

ImportError: cannot import name 'transfer_markers' when testing with pytest

When I run tests for my python project by running the following command:

python setup.py test
(or)
pytest project_name

I get the following error:

.../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'

When I looked it up online, there was almost no mention of that particular error message anywhere. Something similar has happened to me a few times before where previously working code just breaks and it's usually because there's a new version of an important package.

I looked at the pytest release history , and it looks like pytest==4.1.0 has been released a few hours ago (as of this post).

The solution is to revert back to the last stable version of pytest ie pytest==4.0.2 by running the following command:

pip install pytest==4.0.2

The tests are running now.

pytest-asyncio has been updated to 0.10.0

pytest-asyncio is using transfer_markers which is taken out in pytest 4.1.0. Looks like it's fixed and released. Issue #105

EDIT: You can now upgrade pip install pytest-asyncio==0.10.0 to fix this issue.

Or update pytest-asyncio==0.10.0 in your requirements.txt

Don't forget to run pip uninstall pytest to keep your pytest up-to-date if you previously installed pytest 4.0.2 to temporarily fix the issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM