'pytest cannot be executed from Python 3.10.4
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?
Solution 1:[1]
As per comment from Marco Bonelli, pytest had no correct version. So command:
pipenv update pytest
fixed the issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | John |
