Linux command
tox 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Run all test environments
tox
Run specific environment
tox -e [py39]
Run multiple environments
tox -e [py38,py39,lint]
List available environments
tox -l
Recreate environments
tox -r
Run in parallel
tox -p
Pass arguments to test command
tox -- [--verbose]
Recreate and run
tox -r -e [py39]
说明
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.
参数
- -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.
FAQ
What is the tox command used for?
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.
How do I run a basic tox example?
Run `tox` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -e _ENVLIST_, --envlist _ENVLIST_ do in tox?
Environments to run.