Skip to content
Edit this page

Configuration

pytest-uv reads [tool.pytest-uv] from the pyproject.toml in pytest's rootdir. Every key is optional; a value of the wrong type stops pytest with a usage error.

[tool.pytest-uv]
versions = ["3.11", "3.12", "3.13", "3.14"]
venv-dir = ".pytest-uv"
sync-args = ["--no-default-groups", "--group", "test"]
install-args = ["-e", ".", "--group", "test"]
Key Type Default Used by
versions list of strings none --python-versions declared
venv-dir string ".pytest-uv" all modes
sync-args list of strings [] projects with uv.lock
install-args list of strings ["-e", "."] plus groups projects without uv.lock

Changing sync-args or install-args rebuilds the environments on the next run.

versions

The minor versions that --python-versions declared tests.

[tool.pytest-uv]
versions = ["3.11", "3.12", "3.13", "3.14"]

Required for declared; ignored by the other modes.

venv-dir

Where the per-version environments live, relative to pytest's rootdir. Each version uses <venv-dir>/py<version>.

[tool.pytest-uv]
venv-dir = ".cache/pytest-uv"

pytest-uv writes a .gitignore containing * into the directory, so git ignores it.

sync-args

Extra arguments for uv sync, used when uv.lock exists. pytest-uv runs, for each version:

UV_PROJECT_ENVIRONMENT=<venv-dir>/py<version> uv sync --frozen --python <version> <sync-args>

The default, [], installs what uv sync installs: the project, its dependencies and uv's default groups (dev). Common values:

[tool.pytest-uv]
sync-args = ["--no-default-groups", "--group", "test"]  # only the test group
# sync-args = ["--all-extras"]                         # every optional dependency
# sync-args = ["--extra", "postgres"]                  # one extra

See uv sync for every option.

install-args

Arguments for uv pip install, used when there is no uv.lock. pytest-uv runs, for each version:

uv venv --clear --python <version> <venv-dir>/py<version>
uv pip install --python <venv-dir>/py<version>/bin/python <install-args>

The default installs the project in editable mode (-e ., or -e .[test] when the project defines a test extra) and adds --group test and --group dev for each of those dependency groups that pyproject.toml defines.

[tool.pytest-uv]
install-args = ["-e", ".[test]"]                            # an extra
# install-args = ["-e", ".", "-r", "requirements-test.txt"]  # a requirements file

In both modes, pytest, pytest-xdist and pytest-uv are installed afterwards if the environment lacks them.