Choosing versions¶
--python-versions takes one of three values. All of them end in a list of versions
such as 3.11, 3.12, 3.13; each one gets an environment and a worker.
| Value | Versions tested | Missing interpreters |
|---|---|---|
3.11,3.12,3.13 |
Exactly these | Downloaded by uv |
declared |
[tool.pytest-uv] versions |
Downloaded by uv |
auto |
Installed CPython releases allowed by requires-python |
Never used |
Explicit list¶
uv run pytest --python-versions 3.12,3.13
uv run pytest --python-versions 3.13 # one version, in its own environment
Use it to narrow a run, for example to re-run a failure on the one version where it happened (Debugging failures). The list is sorted and duplicates are dropped.
Each entry is passed to uv as a
version request,
so builds that auto never picks can be listed explicitly:
uv run pytest --python-versions 3.13,3.14t # 3.14t: free-threaded 3.14
uv run pytest --python-versions 3.14,3.15 # 3.15: a pre-release, if uv has one
Declared¶
Write the list once, in pyproject.toml:
[project]
requires-python = ">=3.11"
[tool.pytest-uv]
versions = ["3.11", "3.12", "3.13", "3.14"]
uv run pytest --python-versions declared
This is the most predictable mode: the same versions on every machine and in CI,
downloaded when missing. Entries are uv version requests, as in an explicit list.
Without a versions key, declared is a usage error.
To use it on every run, put it in your pytest options:
[tool.pytest.ini_options]
addopts = "--python-versions declared"
Then plain uv run pytest tests every version. Override it for a single run with
-o addopts="" or another --python-versions; the last one on the command line wins.
Auto¶
uv run pytest --python-versions auto
auto reads [project] requires-python, asks uv which interpreters are installed
(uv python list --only-installed --output-format json), and tests each minor version
that satisfies the specifier. It keeps final releases of the default CPython build
only: no pre-releases (3.15.0b4), no free-threaded or debug builds (3.14t), no
PyPy. List those explicitly when you want them.
auto never downloads anything, so it tests what the machine has. That suits a
developer laptop ("everything I have installed") and CI jobs that run
uv python install first (GitHub Actions). On a machine with only
one interpreter, it tests one version. When nothing matches, pytest stops with
pytest-uv: no Python versions matched --python-versions=auto.
To see what auto will choose:
uv python list --only-installed
grep requires-python pyproject.toml
Without --python-versions¶
pytest-uv does nothing: tests run in the current environment, as if the plugin was
not installed, and the python_version fixture returns
None.