Is it possible to run py.test
with different versions of python without plugins (like xdist
) or tox
?

- 13,753
- 17
- 64
- 93
4 Answers
The simplest way to do it is by running the pytest module directly with -m
, for example:
python2.6 -m pytest
Note that you have to have pytest installed for that version of Python. In addition, you need to install all pytest plugins that you are using for that version of Python too.

- 6,298
- 2
- 22
- 34

- 10,068
- 4
- 48
- 53
You can create a standalone pytest script with
py.test --genscript=mypytest
and then do
pythonXY mypytest
to run tests with a particular python version.
You do not need to install pytest for that particular python version as pytest is completely contained in the "mypytest" script.
-
`--genscript` is no longer supported since `pytest 3.0.0` – Pasha Jan 26 '17 at 23:16
VirtualEnv is done to handle those case.
virtualenv is a tool to create isolated Python environments.
Using virtualenv, you will be able to create multiple environements, each one with one plugin you want.

- 78,516
- 15
- 127
- 132
-
Note that you have to install pytest in your virtualenv, rather than invoking the version you might have installed in your regular PATH. – Jack O'Connor Nov 06 '15 at 22:28
-
I installed pytest in my virtual environment but it still uses wrong version :/ $ which pytest $ /home/nurp/.envs/test/bin/pytest replace pytest with py.test just worked. I have no idea when that changed. pytest used to work a while ago... – nurp Nov 15 '18 at 12:58
Using xdist plugin this can be easily done:
py.test -d --tx popen//python=pythonX
runs python version X (2 or 3).
Since this is the first google result of "pytest test multiple versions"
I'm posting this, nevertheless I realize this is not an answer to OP's question of how to do this without plugins.

- 809
- 1
- 16
- 21