Home / Python CI / Chapter 7

Chapter 7: Code Coverage

Dec 14, 2024
7 of 9

Additionally to just running unit tests, we can also track the code coverage. You can use codecov.io/ as a target for your report.

uv add --dev pytest-cov
.github/workflows/code-quality.yml
name: Python Code Quality
on: [push]
jobs:
  lock_file: ...
  linting: ...
	formatting: ...
	type_consistency: ...
  tests:
    runs-on: ubuntu-latest
    needs: [lock_file]
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/actions/setup
      - run: uv run pytest -v --durations=0 --cov --cov-report=xml
      - name: Upload Coverage to Codecov
        uses: codecov/codecov-action@v4
        with:
          token: ${{ secrets.CODECOV_TOKEN }}