Reusable workflow that installs Python dependencies with uv and runs pytest.
uv resolves the Python version from the project's pyproject.toml or .python-version file automatically. uv sync --frozen installs all dependencies from the committed lockfile without modifying it.
Replace
<current-sha>with the current SHA from the root README.
on: [push, pull_request]
jobs:
test:
uses: orangitfi/platform-tooling/.github/workflows/python-test.yml@<current-sha>jobs:
test:
uses: orangitfi/platform-tooling/.github/workflows/python-test.yml@<current-sha>
with:
test-command: "pytest tests/ -v --tb=short"jobs:
test:
uses: orangitfi/platform-tooling/.github/workflows/python-test.yml@<current-sha>
with:
uv-sync-args: "--extra test"jobs:
test:
uses: orangitfi/platform-tooling/.github/workflows/python-test.yml@<current-sha>
with:
working-directory: ./backend
uv-sync-args: "--extra test --extra dev"jobs:
security:
uses: orangitfi/platform-tooling/.github/workflows/python-security-scan.yml@<current-sha>
test:
needs: security
uses: orangitfi/platform-tooling/.github/workflows/python-test.yml@<current-sha>| Input | Default | Description |
|---|---|---|
working-directory |
. |
Directory containing pyproject.toml |
test-command |
pytest |
Command to run via uv run |
uv-sync-args |
"" |
Extra arguments passed to uv sync (e.g. --extra test) |
- Installs uv v0.11.3 with SHA-256 verification
- Runs
uv sync --frozen [uv-sync-args]— installs all dependencies from the committed lockfile, including the correct Python version - Runs
uv run <test-command>in the working directory
uv sync --frozenis strict: ifpyproject.tomlhas changed since the lastuv lock, the sync fails with a clear error. This enforces that the lockfile is always kept up to date.uv runactivates the project venv automatically — no manualsource .venv/bin/activateorPYTHONPATHconfiguration needed- uv downloads and manages the Python interpreter itself, so the test always runs on the exact Python version the project declares, regardless of what the runner has pre-installed
- To run only a subset of tests (e.g. fast unit tests on PR, full suite nightly), use different
test-commandvalues in different workflow triggers. - Add
--covand--cov-report=xmltotest-commandto generate a coverage report. Upload it as an artifact or send it to a coverage service as a subsequent step. - The
uv-sync-argsinput is useful when test dependencies are declared as optional extras inpyproject.toml(e.g.[project.optional-dependencies] test = ["pytest", "httpx"]). Pass--extra testto install them. - If tests require environment variables (database URLs, API keys), pass them as
env:on the calling job. Reusable workflows inherit the caller's environment.