How to Test Against Multiple Python Versions in Parallel

Supporting multiple versions of Python is something we’ve done for a while now on Pinax apps, however, we’ve mostly relied on Travis CI to execute tests in each version. This is inefficient and leads to a lot of follow up commits to fix as well as wasted time as we wait on builds to finish.

The answer is making use of pyenv and detox.

If you haven’t heard of pyenv yet, it’s worth checking out. It makes it a snap to manage both different virtualenvs as well as different versions of Python. You get the virtualenv extensions by installingpyenv-virtualenv and pyenv-virtualenvwrapper.


The simplest way to do this on OS X is to use brew:

brew install pyenv pyenv-virtualenv pyenv-virtualenvwrapper

Then you’ll want to install all the Pythons you want to test with that are in your tox.ini:

pyenv install 2.7.10
pyenv install 3.2.6
pyenv install 3.3.6
pyenv install 3.4.3
pyenv install 3.5.0


You’ll then want to set all these to be global versions:

pyenv global 2.7.10 3.2.6 3.3.6 3.4.3 3.5.0

At this point, exit your terminal and open up a new one and run:

pyenv versions

To make sure all the global ones are set properly.

Now, install detox globally (without being in a virtualenv):

pip install detox

Now in any project with a tox.ini with Python versions you have installed you can simply run detox to run all tests in parallel without getting into a certain environment. detox and tox will take care of creating environments to run tests in and enter those environments, and run tests, all in a parallel.

Sample tox.ini

Here is an example of the tox.ini from pinax-stripe:

Happy testing!


detox testing tox