# pytest-uv vs nox

[nox](<https://nox.thea.codes/>) runs sessions defined as Python functions in `noxfile.py`. A session parametrized over `python=[...]` runs once per version, each in its own virtual environment. With `venv_backend="uv"` (or `nox -db uv`) the environments are created with uv and packages installed with `uv pip`. nox's cookbook shows how to install from `uv.lock` by running `uv sync` with `UV_PROJECT_ENVIRONMENT` set to the session's environment.

## The same task in both

nox, in `noxfile.py`:

```python
import nox


@nox.session(python=["3.11", "3.12", "3.13"], venv_backend="uv", allow_parallel=True)
def tests(session: nox.Session) -> None:
    session.run_install(
        "uv",
        "sync",
        "--frozen",
        "--no-default-groups",
        "--group=test",
        f"--python={session.virtualenv.location}",
        env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
    )
    session.run("pytest", *session.posargs)
```

```bash
uvx nox --parallel auto
```

pytest-uv, in `pyproject.toml`:

```toml
[tool.pytest-uv]
versions = ["3.11", "3.12", "3.13"]
sync-args = ["--no-default-groups", "--group", "test"]
```

```bash
uv run pytest --python-versions declared
```

## Quick comparison

|  | nox with the uv backend | pytest-uv |
| --- | --- | --- |
| Runs | Any Python code and commands per session | pytest |
| Configuration | `noxfile.py` | Command-line option; optional `[tool.pytest-uv]` |
| From `uv.lock` | A `uv sync` call you write (or the [nox-uv](<https://github.com/dantebben/nox-uv>) helper) | Automatically when `uv.lock` exists |
| Parallel | `--parallel`, for sessions with `allow_parallel=True` | Always, one xdist worker per version, one report |
| Reuse | Recreated on every run by default; `-r` (`--reuse-venv=yes`) reuses them | Reused until its inputs change |
| Missing interpreters | `--download-python` (uv or python-build-standalone) | Downloaded by uv |
| pytest options | After `--`, passed through `session.posargs` | Directly |

## Which to choose

**Choose nox** when sessions need logic: conditional installs, several tools, generated files, release tasks. Its sessions are Python, so anything is possible.

**Choose pytest-uv** when the session would only install the project and run pytest per version. You skip the noxfile, keep pytest's own command line, and get one report for all versions.

Both can live in one project: nox for lint, docs and release sessions, pytest-uv for the version matrix.
