Skip to content

Managing Test Environments with tox

tox is a command-line tool used alongside pytest to automate test execution across multiple Python versions, dependency sets, or environments. In this setup, pytest acts as the test runner, while tox orchestrates how and where tests are executed.

An example tox.ini configuration might look like this:

ini
[tox]
envlist = py39, py310

[testenv]
deps = pytest
commands = pytest

[pytest]
addopts = -rsxX -l --tb=short --strict

As shown above, the pytest.ini configuration is also moved into tox.ini when using tox.

Running tox will create isolated virtual environments, install pytest and dependencies, and execute the test suite in each environment. This combination is especially powerful for libraries that need to support multiple Python versions or optional dependencies.