Skip to content
Edit this page

Debugging failures

A test fails on 3.11 and passes on 3.12 and 3.13. These are the ways to get from the report to a fix.

Narrow the run to one version

--python-versions takes a single version too. It reuses the existing environment, so the run starts immediately:

uv run pytest --python-versions 3.11 tests/test_chunks.py -x

All the usual selection options work (-k, -m, a node id, -x).

Re-run last failures with --lf

--lf works, with one catch: pytest's cache stores the ids of failed tests without the version they failed on (tests/test_chunks.py::test_even_split). So --lf re-runs a failed test on every version, including those where it passed:

uv run pytest --python-versions 3.11,3.12,3.13 --lf     # failures, on all three

To re-run them only where they failed, narrow the versions as well:

uv run pytest --python-versions 3.11 --lf -v

Step through with --pdb or breakpoint()

--pdb together with --python-versions is a usage error: xdist workers run in subprocesses without a terminal, and xdist disables --pdb for that reason. To debug interactively, skip xdist and run pytest directly with that version's interpreter. The environment already has pytest, pytest-uv, your project and its dependencies:

.pytest-uv/py3.11/bin/python -m pytest tests/test_chunks.py::test_even_split --pdb

On Windows the interpreter is .pytest-uv\py3.11\Scripts\python.exe.

The test now runs in one process on 3.11, so --pdb, --trace, breakpoint() and -s behave as usual. Without --python-versions, pytest-uv does nothing and the python_version fixture returns None.

If your pytest options always add --python-versions (for example through addopts), clear them for this run:

.pytest-uv/py3.11/bin/python -m pytest tests/test_chunks.py::test_even_split --pdb -o addopts=""

A Python shell on one version

The same interpreter gives you a REPL with the project installed:

.pytest-uv/py3.11/bin/python -c "import chunks; print(list(chunks.chunked('abc', 2)))"

When the environment itself is the problem

  • A dependency resolves differently on one version. Compare uv pip list --python .pytest-uv/py3.11/bin/python with the same command for 3.13.
  • uv failed while building it. The usage error contains uv's message; add -v to see uv's full output while the environment is built.
  • The environment looks stale. Delete it and let the next run rebuild it: rm -rf .pytest-uv/py3.11. See Reuse and rebuilds.