DEV Community

loading...

I wrote a GitHub Action to allow CI with pytest code coverage

alexanderdamiani profile image Alex Damiani ・1 min read

The GitHub Action can be found here:

https://github.com/marketplace/actions/pytester-cov

Please consider starring the repo if you find it useful.


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

  1. It doesn't check subfolders be default.
  2. By default 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.


I've also created a YouTube video that details how to add the GitHub Action to your project, as well as a breakdown of how the Action works:

https://www.youtube.com/watch?v=OOZtW3iF0is&list=PL0dOL8Z7pG3J6t1pqRQiNarBGY-ZnIJcq&index=4

All the code for the video is on GitHub as well, with the link in the video description.


Please consider subscribing if you find the video helpful. I am trying to post a new video every few weeks on various topics surrounding Python and DevOps.

Discussion (0)

pic
Editor guide