Nox
Nox is a command-line tool that automates tasks like testing and linting in isolated virtual environments across one or more Python versions. You define sessions as Python functions in a noxfile.py, and Nox creates an environment for each session, installs dependencies, and runs your commands.
Installation and Setup
Install it from PyPI:
Key Features
- Defines functions in
noxfile.pyusing@nox.sessiondecorator. - Creates isolated environments per session using a selectable backend. It defaults to
virtualenv, but supportsuv, Conda,mamba,micromamba,rattler, andvenv. - Runs sessions across multiple Python versions and filters by Python version at the CLI with
--python. - Downloads missing Python interpreters on demand with
--download-python, usinguvor python-build-standalone, so a session’s Python version doesn’t have to be preinstalled. - Builds test matrices with
nox.parametrize, including readable IDs. - Filters which sessions run using pytest-style keywords (
-k/--keywords) and tags (-t/--tags). - Reuses environments between runs with
--reuse-venv=yes(or-r) to speed up local workflows. - Runs independent sessions concurrently with
-j/--parallel, which individual sessions opt into with@nox.session(allow_parallel=True). - Supports optional helpers like
nox-poetryandnox-uvfor tighter integration with Poetry anduvworkflows.
Usage
Create a noxfile.py in your project directory and define sessions with an optional list of Python versions:
import nox
@nox.session(python=["3.12", "3.13", "3.14"])
def tests(session):
session.install("pytest")
session.run("pytest", "-q")
Run all sessions:
$ nox
List available sessions:
$ nox -l
Select sessions to run:
$ nox -s lint tests
Choose Python versions at the CLI:
$ nox --python 3.12
Reuse environments to speed up local runs:
$ nox --reuse-venv=yes
Switch the default backend, with optional fallbacks:
$ nox --default-venv-backend "uv|virtualenv"
Related Resources
Course
Testing Your Code With pytest
In this video course, you'll learn how to take your testing to the next level with pytest. You'll cover intermediate and advanced pytest features such as fixtures, marks, parameters, and plugins. With pytest, you can make your test suites fast, effective, and less painful to maintain.
For additional information on related topics, take a look at the following resources:
- pytest Tutorial: Effective Python Testing (Tutorial)
- Python Virtual Environments: A Primer (Tutorial)
- Continuous Integration With Python (Course)
- Managing Dependencies With Python Poetry (Course)
- Effective Testing with Pytest (Quiz)
- Working With Python Virtual Environments (Course)
- Python Virtual Environments: A Primer (Quiz)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 12, 2026