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.

Patrick Altman
The Pinax Project
2 min readDec 8, 2015

--

Photo by Jens Lelie on Unsplash

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.

Installation

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

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

Setup

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

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

To make sure all the global ones are set properly.

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

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:

The tox.ini from pinax-stripe

Happy testing!

Originally published at blog.pinaxproject.com on December 8, 2015.

--

--