...

/

Setting Up Environments with tox

Setting Up Environments with tox

Learn how to set up a testing environment with Tox using Python.

We'll cover the following...

As you might already know, tox is a tool that automates building virtual Python environments. Those environments are isolated and straightforward to rebuild while having support for multiple Python versions at the same time in different environments.

Most of the time, tox is used to directly run unit tests of a program, with a file as simple as:

Press + to interact
[testenv]
deps=nose
commands=nosetests

Such a file makes sure that the tests are run in a clean Python environment with the right dependencies installed, as specified by your packaging tools.

Since it is possible to run any command by setting the commands parameter, it is easy to envision a system where you could start other services before running your tests. Therefore, a simplistic technique to run integration tests with memcached, for example, would be:

Press + to interact
[testenv]
commands=memcached -p 12345 &
nosetests
...