Tox-Driven Python Development

Going through Julian Berman's jsonschema repo (some of the cleanest Python code I've read, by the way), I stumbled upon a recommendation that greatly improved my Python workflow. I'm talking about Tox, the Python testing automaton.

Tox allows you to test your code against multiple versions of Python (yes, PyPy included!) with a single command:

$ tox

It uses virtualenv to create a virtual Python environment for each Python version you want to support, installs your dependencies as well as the package you are currently developing in each of these enviroments and runs a sequence of testing commands of your choice in each environment.

Tox is great for Test-driven development (TDD). In fact, I no longer need to activate a virtual environment during development. My workflow now looks like this:

  1. Write a test
  2. Write some code
  3. Run tox and tweak code until test passes

If you think your code works on all versions of Python just because it works on your development version, think again!


install_requires = [
dependency_links = [
    # Patched version to support a special feature
include tox.ini
# If your tests aren't part of the distributed package, make sure to include them
recursive-include tests *
envlist = py26, py27, pypy

deps =
commands =

Good luck!