Python pytest with coverage upload
Python pytest with coverage upload
Python's test pipeline is straightforward: install dependencies (pip + cache), run pytest with coverage, upload the report. The only platform-specific bit is how coverage data surfaces.
Conversion notes
- •Codecov's uploader script works identically across all four platforms — only the cache shape changes.
Side-by-side implementation
name: python
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: pip
- run: pip install -r requirements.txt -r requirements-dev.txt
- run: pytest --cov=src --cov-report=xml
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
stages: [test]
test:
stage: test
image: python:3.11
cache:
paths: [.cache/pip]
variables:
PIP_CACHE_DIR: $CI_PROJECT_DIR/.cache/pip
script:
- pip install -r requirements.txt -r requirements-dev.txt
- pytest --cov=src --cov-report=xml --junitxml=report.xml
artifacts:
reports:
junit: report.xml
coverage_report:
coverage_format: cobertura
path: coverage.xml
version: 2.1
jobs:
test:
docker: [{ image: cimg/python:3.11 }]
steps:
- checkout
- restore_cache:
keys: [pip-{{ checksum "requirements.txt" }}]
- run: pip install -r requirements.txt -r requirements-dev.txt
- save_cache:
key: pip-{{ checksum "requirements.txt" }}
paths: [~/.cache/pip]
- run: pytest --cov=src --cov-report=xml
- run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t $CODECOV_TOKEN -f coverage.xml
workflows:
main:
jobs: [test]
image: python:3.11
definitions:
caches:
pip: ~/.cache/pip
pipelines:
default:
- step:
name: test
caches: [pip]
script:
- pip install -r requirements.txt -r requirements-dev.txt
- pytest --cov=src --cov-report=xml
- curl -Os https://uploader.codecov.io/latest/linux/codecov
- chmod +x codecov
- ./codecov -t $CODECOV_TOKEN -f coverage.xml
Related Tools
YAML Formatter
Format and validate YAML. Convert YAML to JSON or JSON to YAML. Supports 2 and 4 space indentation.
Cron Builder
Visual builder for cron-job schedules.
Gitignore Generator
Generate .gitignore files for any language, framework, or IDE — 100+ templates, 100% client-side.
JSON Schema Generator
Generate a JSON Schema from one or more sample JSONs — drafts 2020-12, 2019-09, 7, 6, 4. Detects formats (date-time, email, uuid, ipv4, uri), extracts $defs, validates with AJV, and exports to YAML, TypeScript, and Zod. 100% in your browser.
AI Coding Rules
Curated rules-file library and generator for Cursor, Claude Code, GitHub Copilot, Windsurf, Cline, Aider, Continue, and Cody. Browse 20 hand-crafted .cursorrules / CLAUDE.md / copilot-instructions.md files for popular stacks, build a custom one with the wizard, or convert any rules file between AI-tool formats.