You can find the answer @falsetru does not work if you installed pytest system wide AFTER you installed in virtualenv, just like me.
(Quick note: py.test is an old version of the command, pytest is recommended, but what applies to one refers to another)
You can find out where pytest is loaded by calling which pytest .
As you can see, my pytest points to one that is not in virtualenv:
(env) ~/projects/test/website $ which python /home/andrew/projects/test/website/env/bin/python (env) ~/projects/test/website $ which pytest /home/andrew/.local/bin/pytest
Here's the proof that pytest IS is installed in virtualenv:
(env) ~/projects/test/website $ pip install pytest Requirement already satisfied: pytest in ./env/lib/python3.5/site-packages Requirement already satisfied: py>=1.4.29 in ./env/lib/python3.5/site-packages (from pytest)
And hash -r does not matter (since the new installation did not complete):
(env) ~/projects/test/website $ hash -r (env) ~/projects/test/website $ which pytest /home/andrew/.local/bin/pytest
The solution is to uninstall and reinstall pytest in virtualenv,
(env) ~/projects/test/website $ pip uninstall pytest ... (env) ~/projects/test/website $ pip install pytest ... (env) ~/projects/test/website $ which pytest /home/andrew/projects/test/website/env/bin/pytest
If for some reason you cannot reinstall, one way around this is to call pytest as a module through python in your virtualenv:
python -m pytest
andyhasit
source share