Why pytest-uv?¶
The problem¶
A library that says requires-python = ">=3.11" makes a promise about four or five
Python versions. Most developers test one of them: the one in .venv. The others are
tested by CI, a few minutes after the push, one matrix job per version, and the
failure is read in a web page instead of the terminal.
Version-specific breakage is common and easy to write:
- a standard-library addition used too early (
itertools.batchedis 3.12+,typing.overrideis 3.12+,warnings.deprecatedis 3.13+); - syntax from a newer version (PEP 695
def f[T](...)is 3.12+); - a dependency that dropped a version, or behaves differently on it;
- a deprecation that became an error in the newest release.
Running the tests locally on every version usually means a second tool: tox or nox,
with their own configuration file, environment names and command line, or a shell
loop that rebuilds .venv for each version.
What pytest-uv does¶
It makes "every supported version" an option of the pytest you already run:
uv run pytest --python-versions auto
- No second configuration. Versions come from the command line, from
requires-python, or from a short[tool.pytest-uv]table. Dependencies come from youruv.lockand dependency groups. - One report. Every version runs in the same pytest session, as one pytest-xdist worker each; failures from all versions are listed together, and the exit code covers all of them.
- Fast after the first run. Environments are built in parallel by uv and reused until the lock file or settings change. Source changes need no rebuild.
- Your
.venvis left alone. Each version has its own environment under.pytest-uv/; nothing is re-synced in the project environment. - Every pytest option still works:
-k,-m,--lf,-x, markers, fixtures and plugins, on each version.
When to use something else¶
- You run more than pytest. Linters, type checkers, docs builds and packaging checks per version are what tox and nox are for.
- The matrix is not Python versions. Testing against several versions of a dependency (Django 4.2 and 5.2), or with and without an extra, needs tox or nox.
- You want one version spread over many CPUs. That is plain
pytest -n auto(pytest-xdist alone). pytest-uv gives each version one worker, and refuses-ntogether with--python-versions. - Versions need different machines. Operating systems, architectures or system libraries still need a CI matrix; pytest-uv can run inside each job.
- You can't use uv. pytest-uv builds every environment with it.