Skip to content
Edit this page

GitHub Actions

One job, every Python version, one pytest report. The pytest-uv action does the setup:

# .github/workflows/tests.yml
name: Tests

on:
  push:
    branches: [main]
  pull_request:

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false
      - uses: jirikuncar/pytest-uv@v0.1.0  # pin a release tag or commit SHA
        with:
          python-versions: auto
          pytest-args: -v
Input Default Meaning
python-versions auto auto (final CPython releases uv can download that match requires-python), declared, or 3.12,3.13
pytest-args empty extra pytest arguments, split like a shell command line
working-directory . directory with pyproject.toml
sync true run uv sync first, with --locked when uv.lock exists
uv-version latest uv version for astral-sh/setup-uv
enable-cache true cache uv's package cache and Python downloads

The python-versions output holds the resolved list. pytest-uv must be a dev dependency of the project (uv add --dev pytest-uv). The action installs uv and the interpreters, syncs the project, then runs pytest --python-versions <resolved list>. Unlike the plugin's own auto, which only sees installed interpreters, the action's auto reads uv's download list, so new runners test every supported version without a list to maintain. pytest-uv's own CI runs its test suite on Python 3.11 to 3.15 this way.

Without the action

The same steps by hand:

# .github/workflows/tests.yml
name: Tests

on:
  push:
    branches: [main]
  pull_request:

permissions:
  contents: read

jobs:
  test:
    name: Tests on every supported Python
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false

      - uses: astral-sh/setup-uv@36300bab3f61b84e19f32b6bd26b7897f3c7e951 # v10.4.2
        with:
          version: "0.13.13"

      # `auto` tests every installed interpreter that satisfies requires-python.
      - name: Install Python versions
        run: uv python install 3.11 3.12 3.13 3.14

      - name: Install the project
        run: uv sync --locked

      - name: Run tests on each version
        run: uv run pytest --python-versions auto -v

The same file is in examples/github-actions.

  • uv python install puts the interpreters where auto finds them. You need neither actions/setup-python nor the python-version input of setup-uv, which selects a single version.
  • uv sync --locked installs the controller environment (.venv) and fails if uv.lock is out of date. pytest-uv then builds one environment per version from the same lock file.
  • Actions are pinned by commit SHA, with the release in a comment, so a moved tag can't change what runs.

Pick the versions explicitly

auto uses every matching interpreter on the runner, including ones that were there before uv python install (Ubuntu 24.04 ships Python 3.12). For an exact list, keep it in pyproject.toml:

[tool.pytest-uv]
versions = ["3.11", "3.12", "3.13", "3.14"]
      - name: Run tests on each version
        run: uv run pytest --python-versions declared -v

With declared, uv downloads any missing version itself, so the uv python install step becomes optional; keeping it makes the download show up as its own step.

One job or a matrix?

One job with pytest-uv Matrix, one job per version
Checkout, uv setup, uv sync Once Once per version
Results One pytest summary, one exit code One job status per version
Runs in parallel Yes, one xdist worker per version on the same runner Yes, on separate runners
Different OS per version No Yes

The two combine: a matrix over operating systems, each job running pytest --python-versions declared.

jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false
      - uses: astral-sh/setup-uv@36300bab3f61b84e19f32b6bd26b7897f3c7e951 # v10.4.2
        with:
          version: "0.13.13"
      - run: uv sync --locked
      - run: uv run pytest --python-versions declared

Caching

setup-uv caches uv's download and wheel cache (its enable-cache input), which makes building the per-version environments mostly a matter of linking files. The .pytest-uv/ directory itself is cheap to rebuild and refers to interpreters by absolute path, so don't cache it between runs.