27

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

Vladimir Keleshev
  • 13,753
  • 17
  • 64
  • 93

4 Answers4

23

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.

Pasha
  • 6,298
  • 2
  • 22
  • 34
Jack O'Connor
  • 10,068
  • 4
  • 48
  • 53
6

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.

The Demz
  • 7,066
  • 5
  • 39
  • 43
hpk42
  • 21,501
  • 4
  • 47
  • 53
2

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.

Cédric Julien
  • 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
0

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.

Ajasja
  • 809
  • 1
  • 16
  • 21