when I am trying to run my test through command line
py.test file_name.py
I got this error:
py.test: error: unrecognized argum
On my Ubuntu, I had also similar issue which was caused by having wrong binary for pytest
:
py.test --version
This is pytest version 4.6.11, imported from /home/myhome/.local/lib/python2.7/site-packages/pytest.pyc
But my current python setup (python --version
) was 3.7.7.
. I had to run this instead:
python -m pytest --version
pytest 6.2.1
Similarly you can run python -m pytest file_name.py
or for coverage python -m pytest --cov=my_project tests/
.
I always recommend to check this especially when there are any issues and I think it's a good practice to run this with -m
instead of using pytest
directly as it may easily happen it points to different version than the one that should be used within your current python environment. (See similar explanation here.)