Skip to content

A GitHub action to provide pytest coverage reporting. Works with pyproject.toml or setuptools based projects.

License

Notifications You must be signed in to change notification settings

JotaFan/pycoverage

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

pycoverage

Initialy forked from pytest-reporter Using github-push-action

This GitHub action runs python tests using pytest and creates a comment for PR with a coverage table. It supports projects with the most popular python package managers (pip, poetry, pipenv) Optionally can commit the coverage badge into the branch.

made-with-python license

Python Packages Used

Optional Inputs

  • requirements-file

    • requirements filepath for project
    • if left empty will default to requirements.txt
    • necessary if you use pip python package manager
  • pytest-root-dir

    • root directory to recursively search for .py files
  • pytest-tests-dir

    • directory with pytest tests
    • if left empty will identify test(s) dir by default
  • cov-omit-list

    • list of directories and/or files to ignore
  • cov-threshold-single

    • fail if any single file coverage is less than threshold
  • cov-threshold-total

    • fail if the total coverage is less than threshold
  • async-tests

    • Add support for async tests
  • poetry-version

    • Poetry version to be used. The latest version is used by default
  • poetry-groups

    • Poetry group names with the dependencies for the tests
  • package-extras

    • Package extras with the dependencies for the tests, or dev-requirement file if pip
  • output

    • Output path to write the coverage badge
  • overwrite

    • Overwrite an existing coverage badge.
  • working_branch

    • Working_branch
  • commit_badge

    • Boolean to either make a commit on the coverage badge or not

Template workflow file

name: pycoverage workflow

on: [pull_request]

jobs:
  tests:
    runs-on: ubuntu-latest
    name: Unit tests
    steps:
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }} # be sure to add this ref on your checkout
      - uses: actions/setup-python@v2
        with:
          python-version: '3.9.6' # Define your project python version
      - id: run-tests
        uses: JotaFan/pycoverage@v1.0.0
        with:
          cov-omit-list: tests/*
          cov-threshold-single: 85
          cov-threshold-total: 90
          async-tests: true
          poetry-version: 1.4.2
          package-extras: dev,tests
          github_token: ${{ secrets.github_token }}
          working_branch: ${{ steps.extract_branch.outputs.branch }}

Add the badge to your README.md

<!-- README.md -->
+ [![cov](https://<you>.github.io/<repo>/badges/coverage.svg)](https://github.com/<you>/<repo>/actions)

Replace the <you> and <repo> above, like:

If you feel generous and want to show some extra appreciation:

Support this project with a ⭐

"Buy Me A Coffee" Support via PayPal

About

A GitHub action to provide pytest coverage reporting. Works with pyproject.toml or setuptools based projects.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published