Python Testing

Framework Configuration

Key Requirements

  • Coverage report must be in LCOV format
  • Report must be saved as coverage/lcov.info
  • Report must be uploaded as a GitHub Actions artifact named coverage-report

The most common approach for Python test coverage is using pytest with pytest-cov. These tools can generate coverage reports in LCOV format, which is compatible with GitAuto's coverage analysis.

Installation

terminal
pip install pytest pytest-cov

Setting Up GitHub Actions

Create a workflow file in .github/workflows/ directory. The filename can be anything you prefer (e.g. python-coverage.yml). Add the following content to your workflow file:

python-coverage.yml
name: Pytest Coverage

on:
  push:
  workflow_dispatch:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.x'
          
      - name: Install dependencies
        run: pip install pytest pytest-cov
          
      - name: Run tests with coverage
        run: python -m pytest --cov --cov-report=lcov:coverage/lcov.info
          
      - name: Upload coverage reports
        uses: actions/upload-artifact@v4
        with:
          name: coverage-report
          path: coverage/lcov.info

Key Configuration Points

  • Run tests with --cov and --cov-report=lcov flags
  • Upload the report as an artifact named coverage-report
  • Ensure the report is saved as coverage/lcov.info

Viewing Coverage Reports

After your workflow runs successfully, GitAuto automatically processes the coverage reports and displays them in the Coverage Dashboard. The data updates whenever:

  • You push to any branch (except master)
  • You push additional commits to a pull request
  • You manually trigger the workflow

About LCOV: LCOV (Linux Code Coverage) is a standard format for code coverage data. It's pronounced "el-cov" and is widely supported by various tools and services.