tox

4.51.0 · active · verified Sun Mar 29

tox is a generic virtual environment management and test command-line tool for Python projects. It automates and standardizes testing across various Python versions, interpreters, and dependency configurations, serving as a powerful frontend for local development and Continuous Integration servers. Currently at version 4.51.0, tox maintains an active development pace with frequent patch and minor releases, often on a monthly or bi-weekly cadence.

Warnings

Install

Quickstart

This quickstart sets up a basic Python project with a `pyproject.toml` file configured for `tox`. It defines two environments: `py` (to run pytest) and `lint` (to run ruff). After running this Python script, navigate to the directory where it created the `pyproject.toml` and `my_package` folder, then simply execute `tox` in your terminal. tox will automatically create isolated virtual environments, install dependencies, and run the specified commands.

import os

# Create a dummy project structure
os.makedirs('my_package/tests', exist_ok=True)
with open('my_package/main.py', 'w') as f:
    f.write('def add(a, b):\n    return a + b')
with open('my_package/tests/test_main.py', 'w') as f:
    f.write('from my_package.main import add\n\ndef test_add():\n    assert add(1, 2) == 3')

# Create pyproject.toml for tox configuration
with open('pyproject.toml', 'w') as f:
    f.write('''
[project]
name = "my_package"
version = "0.1.0"

[tool.tox]
env_list = ["py", "lint"]

[tool.tox.env_run_base]
description = "Run the test suite with pytest"
deps = ["pytest>=8"]
commands = ["pytest {posargs:tests}"]

[tool.tox.env.lint]
description = "Run linters"
skip_install = true
deps = ["ruff"]
commands = ["ruff check {posargs:.}"]
''')

print("Project setup complete. Now run 'tox' in your terminal.")

view raw JSON →