I already saw one old post regarding this topic - An error while trying to execute tests on python 3.10 with pytest,
I am having the same problem, Python 3.10.4 and pytest 7.1.2, when I start command:
$ pipenv run pytest
I get an error:
$ pipenv run pytest
============================= test session starts =============================
platform win32 -- Python 3.10.4, pytest-4.0.0, py-1.7.0, pluggy-0.8.0
rootdir: **DIR**, inifile:
collected 0 items / 1 errors
=================================== ERRORS ====================================
____________________ ERROR collecting test/test_person.py _____________________
<frozen importlib._bootstrap>:939: in _find_spec
???
E AttributeError: 'AssertionRewritingHook' object has no attribute 'find_spec'
During handling of the above exception, another exception occurred:
**LOCAL_PATH**\.virtualenvs\iamdb-2ZawZA6J\lib\site-packages\py\_path\local.py:668: in pyimport
__import__(modname)
<frozen importlib._bootstrap>:1027: in _find_and_load
???
<frozen importlib._bootstrap>:1002: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:941: in _find_spec
???
<frozen importlib._bootstrap>:915: in _find_spec_legacy
???
**LOCAL_PATH**\.virtualenvs\iamdb-2ZawZA6J\lib\site-packages\_pytest\assertion\rewrite.py:162: in find_module
source_stat, co = _rewrite_test(self.config, fn_pypath)
**LOCAL_PATH**\.virtualenvs\iamdb-2ZawZA6J\lib\site-packages\_pytest\assertion\rewrite.py:412: in _rewrite_test
co = compile(tree, fn.strpath, "exec", dont_inherit=True)
E TypeError: required field "lineno" missing from alias
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.16 seconds ===========================
Anyone has a solution?
I faced the same issue when using poetry. In my case, pytest
was set to v5.2:
[tool.poetry.dev-dependencies]
pytest = "^5.2"
After updating pytest
to ^7.1.2
, things started working.
poetry add -D pytest@latest
[tool.poetry.dev-dependencies]
pytest = "^7.1.2"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With