# pytest-uv vs a shell loop over `uv run`

uv can already run a command on any Python version, so the shortest multi-version test run needs no plugin at all:

```bash
for v in 3.11 3.12 3.13; do
  uv run --python "$v" pytest || exit 1
done
```

## What the loop does

In a project, `uv run --python 3.11` makes the **project environment** match: when `.venv` was created for another version, uv removes it, creates it again for 3.11 and syncs it. The next iteration does the same for 3.12. Each run therefore rebuilds `.venv`, and after the loop `.venv` is left on the last version of the list, not the one your editor and `.python-version` expect.

Two ways to keep `.venv` as it is:

```bash
# A throwaway environment per run (rebuilt each time, from uv's cache)
for v in 3.11 3.12 3.13; do
  uv run --isolated --python "$v" pytest || exit 1
done

# A persistent environment per version
for v in 3.11 3.12 3.13; do
  UV_PROJECT_ENVIRONMENT=".venv-$v" uv run --python "$v" pytest || exit 1
done
```

The second form is close to what pytest-uv does for each version.

## Quick comparison

|  | Shell loop | pytest-uv |
| --- | --- | --- |
| Dependencies | None beyond uv | pytest-uv as a dev dependency |
| Runs | Anything, not only pytest | pytest |
| Versions run | One after another (unless you background them and collect exit codes) | In parallel |
| Results | One pytest summary per version, scrolled past each other | One report, one exit code |
| `.venv` | Rebuilt per version, unless `--isolated` or `UV_PROJECT_ENVIRONMENT` | Untouched |
| Version list | In the script | Command line, `declared`, or `auto` from `requires-python` |
| Portable | POSIX shell; another script for Windows | Wherever pytest runs |

## Which to choose

**Choose the loop** for a one-off check, for commands other than pytest, or where adding a test dependency is not an option. Use `--isolated` or `UV_PROJECT_ENVIRONMENT` so it does not churn `.venv`.

**Choose pytest-uv** when you run the matrix regularly: versions run in parallel, the report is one, the version list can come from `requires-python`, and `.venv` stays on the version you develop with.
