Tox is a tool for automate testing in Python. It does so by reading
a tox.ini file where we specify the environments we want to test, and it will create a brand new
virtual environment for that setup and run the test suite against it.
Let’s start by installing tox and add it to our requirements.txt file.
(django-foobar):~/django-foobar$ pip install tox
(django-foobar):~/django-foobar$ echo “tox” >> requirements.txt
Create a new file tox.ini in the projects working directory and paste the content below.
[tox]
envlist =
py27-django1.6,
py34-django1.8
[django1.6]
deps =
Django>=1.6,<1.7
[django1.8]
deps =
Django>=1.8,<1.9
[testenv]
commands =
python {toxinidir}/setup.py test
[testenv:py27-django1.6]
basepython = python2.7
deps =
{[django1.6]deps}
[testenv:py34-django1.8]
basepython = python3.4
deps =
{[django1.8]deps}
As you can see we have a [tox] block in which we defines a list of environments we want to test.
Next, we define some blocks for the different Django versions we want to test. The [testenv] block
defines the command we want to run, and finally we combine the [testenv] with the different version
blocks in order to fire up the test runner.