# Version-specific tests

Every test runs on every version. Some tests only make sense on some of them, and some failures are expected on one of them.

## Skip or expect a failure with `sys.version_info`

The usual pytest markers work, because each worker evaluates them in its own interpreter:

```python
import sys

import pytest


@pytest.mark.skipif(sys.version_info < (3, 13), reason="batched(strict=True) is 3.13+")
def test_batched_strict():
    from itertools import batched

    with pytest.raises(ValueError):
        list(batched("abc", 2, strict=True))


@pytest.mark.xfail(sys.version_info >= (3, 14), reason="upstream bug, see #123", strict=True)
def test_known_regression():
    ...
```

## The `python_version` fixture

`python_version` is a session-scoped fixture with the version the current worker was started for, as a string such as `"3.13"` (exactly as requested, so `"3.14t"` for a free-threaded worker), or `None` when pytest runs without `--python-versions`:

```python
def test_cache_file_name(tmp_path, python_version):
    suffix = python_version or "local"
    path = tmp_path / f"cache-{suffix}.json"
    path.write_text("{}")
    assert path.exists()
```

The fixture comes from pytest-uv installed in each worker's environment, so it does not exist on workers older than Python 3.11, which pytest-uv cannot be installed into.

Use it to name per-version output files (coverage data, snapshots, logs) so workers don't overwrite each other, or to include the version in a message. To decide what the code under test should do, prefer `sys.version_info`: it also works without pytest-uv.

## The report header

With `--python-versions`, pytest's header has a line with each tested version and the interpreter's full version:

```text
platform linux -- Python 3.13.18, pytest-9.2.0, pluggy-1.7.0
pytest-uv: 3.11 (3.11.18), 3.12 (3.12.16), 3.13 (3.13.18)
```

The `platform` line shows the controller's own Python, the one in your `.venv`, which runs no tests.

## Failures per version

xdist reports a failure once per worker. With `-v`, xdist first prints each worker's interpreter, then prefixes every result with the worker id:

```text
[gw0] linux Python 3.11.18 cwd: /home/you/chunks
[gw1] linux Python 3.12.16 cwd: /home/you/chunks
[gw2] linux Python 3.13.18 cwd: /home/you/chunks
...
[gw0] [ 25%] FAILED tests/test_chunks.py::test_even_split
[gw2] [ 50%] PASSED tests/test_chunks.py::test_even_split
```

Workers are created in version order, so `gw0` is the lowest version tested.
