DEV Community


Automate pytest code coverage checks with GitHub Actions

Alex Damiani
A Python enthusiast, dabbling in other stuff when I can.
・1 min read

There are four problems with pytest code coverage out-of-the-box.

  1. It doesn't check subfolders be default.
  2. It includes the test(s) directory which biases the total code coverage upwards.
  3. It doesn't return an exit code if the code coverage threshold is not met.
  4. It doesn't allow setting a minimum code coverage threshold for individual files.

Points 1 and 2 can be solved by using a .coveragerc file, but having to manually update the file can become cumbersome fast.

The GitHub Action I've written aims to solve all of these issues. I also provide a sample workflow file that uses two other actions as well to automatically create issues and commit comments in your repo with the pytest code coverage table as a markdown table.

If you find the video helpful you can greatly help me by doing one or all of:

Discussion (0)