LinuxCommandLibrary

tox

Automate Python testing across versions

TLDR

Run all test environments

$ tox
copy
Run specific environment
$ tox -e [py39]
copy
Run multiple environments
$ tox -e [py38,py39,lint]
copy
List available environments
$ tox -l
copy
Recreate environments
$ tox -r
copy
Run in parallel
$ tox -p
copy
Pass arguments to test command
$ tox -- [--verbose]
copy
Recreate and run
$ tox -r -e [py39]
copy

SYNOPSIS

tox [-e envs] [-r] [-p] [-l] [options] [-- testargs_]

DESCRIPTION

tox automates testing Python packages across multiple Python versions and environments. It creates isolated virtualenvs, installs packages, and runs tests.
Configuration in tox.ini or pyproject.toml defines environments. Each environment specifies: Python version, dependencies, and commands to run. Common setups test multiple Python versions (py38, py39, py310) plus linting environments.
Environment creation installs the package in development mode plus test dependencies. This catches installation issues early. Recreate mode (-r) rebuilds environments from scratch.
Parallel mode (-p) runs environments simultaneously, speeding up multi-version testing on machines with multiple cores. Output is collected and displayed after completion.
Beyond testing, tox runs any command: linting (flake8, mypy), documentation builds (sphinx), formatting checks. Multiple commands chain in sequence.
The double-dash (--) passes arguments to the test command, enabling pytest flags or test selection without modifying tox.ini.

PARAMETERS

-e ENVLIST, --envlist ENVLIST

Environments to run.
-r, --recreate
Recreate virtual environments.
-p, --parallel
Run environments in parallel.
-l, --list
List environments.
-a, --listenvs-all
List all environments including generated.
--devenv PATH
Create development environment.
-c FILE, --conf FILE
Configuration file path.
--skip-missing-interpreters
Skip environments without interpreter.
-v, --verbose
Verbose output.
-q, --quiet
Quiet output.
--notest
Install but don't test.
--sdistonly
Only create source distribution.
--result-json FILE
Write results as JSON.
--
Pass remaining args to test command.

CAVEATS

Python versions must be installed for their environments. Initial environment creation downloads dependencies. Parallel mode may hit resource limits. Complex configurations can be hard to debug. Some CI systems prefer simpler approaches.

HISTORY

tox was created by Holger Krekel (creator of pytest) around 2010 to solve multi-Python testing. It became the standard tool for Python package testing, used by major projects. Version 4 (2022) brought significant improvements and pyproject.toml support.

SEE ALSO

pytest(1), nox(1), virtualenv(1), hatch(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community