$ pyenv versions
pyenv shell 3.5.2
$ python --version
==================================================================== test session starts ====================================================================
platform linux2 -- Python 2.7.6, pytest-3.0.3, py-1.4.31, pluggy-0.4.0 -- /usr/bin/python
Bottom line: run
python -m pytest, or
As I can see,
/usr/bin/pytest (that belongs to the system package manager's
python-pytest package) has a shebang
!#/usr/bin/python since it corresponds to the system python's installation.
pyenv, as its
README.md says, does not replace
/usr/bin/python - because it indeed should not be replaced to avoid breaking system packages.
Instead, it adds its directory to
PATH and inserts a launcher there which is what gets invoked when you type "
python". As you probably guessed, this hack is ignored by a shebang like the above - as it should.
python -m pytest will make whichever
python that launches itself use the package from its installation.
pytest for your other Python version may include versioned executables on the
py.test-3.6) depending on the way you installed it.
python36-pytest- this is virtually guaranteed.
pip, it only creates an unversioned executable (though you can create a versioned one yourself). Moreover, if you install the same package for a different Python version but with the same
--prefix, it will overwrite the existing one's executable.
pyenv only switches the main
python executable, not ones for its various packages. So, it doesn't help you "switch" the
pytest command in any way, you're on your own here as far as it's concerned.