Python tox

From wikinotes

Tox is built on top of your unittest suite, it's goals are to automate the creation of virtualenvs for several different versions of python and run tests in each of them. This is tremendously helpful. On top of this, tox allows you to

  • define multiple environments (including sub-environments to share dependencies etc)
  • define a custom set of commands to run within each environment
  • restrict tests to only specific versions of python (despite you listing several test candidates)


You can also take advantage of tox's ability to run custom commands to perform common operations like:

  • test specific versions of a library (for specific versions of python)
  • build documentation
  • run unittests

Documentation

official docs https://tox.readthedocs.io/en/latest/index.html
official docs: config https://tox.readthedocs.io/en/latest/config.html
official docs: examples https://tox.readthedocs.io/en/latest/examples.html
official docs: plugins https://tox.readthedocs.io/en/latest/plugins.html

Tutorials

tutorial https://alexgaynor.net/2010/dec/17/getting-most-out-tox/

Locations

.tox/dist results of seutp.py build
.tox/log test results logged
.tox/pyXX virtualenvs for python version

Usage

# <package>/tox.ini   (same dir as setup.py)
[tox]
envlist = py27,py38

[testenv]   ## it is important that you name this environment testenv, or your tests do not run!
deps=
  pytest
  pytest-runner
  setuptools

commands=
  python setup.py test {posargs}   # posargs refers to arguments issued after '--' on commandline
tox          # run tests in all configured python environments
tox -l       # list environments
tox -e py38  # run only py38