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
GitHub Actions
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 }}
GitLab CI
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
CircleCI
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]
Bitbucket Pipelines
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
More Developer Tools- YAML FormatterFormat and validate YAML. Convert YAML to JSON or JSON to YAML. Supports 2 and 4 space indentation.Free • In browser
- Cron BuilderVisual builder for cron-job schedules.Free • In browser
- Gitignore GeneratorGenerate .gitignore files for any language, framework, or IDE — 100+ templates, 100% client-side.Free • In browser
Also useful: JSON Schema GeneratorAI Coding Rules