Run tests and upload coverage workflow (Pringled/pyversity)
The Run tests and upload coverage workflow from Pringled/pyversity, explained and optimized by Latchkey.
CI health: F - at risk
Run this on Latchkey for self-healing, caching, and up to 58% lower cost.
Grade your own workflow free or run it on Latchkey →What it does
This is the Run tests and upload coverage workflow from the Pringled/pyversity repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Run tests and upload coverage
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
name: Run tests with pytest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Create and activate a virtual environment (Unix)
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv .venv
echo "VIRTUAL_ENV=.venv" >> $GITHUB_ENV
echo "$PWD/.venv/bin" >> $GITHUB_PATH
# Install dependencies using uv pip
- name: Install dependencies
run: make install-no-pre-commit
# Run tests with coverage
- name: Run tests under coverage
run: make test
# Upload results to Codecov
- name: Upload results to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
The same workflow, on Latchkey
Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.
name: Run tests and upload coverage on: push: branches: - main pull_request: branches: - main concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: test: timeout-minutes: 30 name: Run tests with pytest runs-on: ${{ matrix.os }} strategy: matrix: os: ["ubuntu-latest"] python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] fail-fast: false steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }} uses: actions/setup-python@v5 with: cache: 'pip' python-version: ${{ matrix.python-version }} allow-prereleases: true - name: Create and activate a virtual environment (Unix) run: | curl -LsSf https://astral.sh/uv/install.sh | sh uv venv .venv echo "VIRTUAL_ENV=.venv" >> $GITHUB_ENV echo "$PWD/.venv/bin" >> $GITHUB_PATH # Install dependencies using uv pip - name: Install dependencies run: make install-no-pre-commit # Run tests with coverage - name: Run tests under coverage run: make test # Upload results to Codecov - name: Upload results to Codecov uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }}
What changed
- Cancel superseded runs when a branch or PR gets a newer push.
- Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
1 third-party action is referenced by a movable tag. Pin it to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.
What Latchkey heals here
This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:
- Network fetches
This workflow runs 1 job (5 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.