python-project-template icon indicating copy to clipboard operation
python-project-template copied to clipboard

Add code coverage calculation to pre-commit stages

Open delucchi-cmu opened this issue 2 years ago • 2 comments

I'm bummed when everything in pre-commit passes locally, then the github workflow lets me know that there's one new line that doesn't have test coverage.

Always aiming for 100% is a high bar, but even a warning that you're reducing coverage would be great!

delucchi-cmu avatar Nov 27 '23 19:11 delucchi-cmu

It would be nice if we could output the total coverage during the pre-commit step. This would give a heads up to let the user know that the github workflow might fail.

drewoldag avatar Dec 15 '23 19:12 drewoldag

We're already calculating the code coverage amounts, so this would be a matter of twiddling with the output/verbosity options to get something useful. The best I've come up with is below, and is basically using the pytest command $ python -m pytest -qq --cov=./src --cov-report=term-missing:skip-covered

$ pre-commit
Check template version...................................................Passed
- hook id: check-lincc-frameworks-template-version
- duration: 0.08s
Clear output from Jupyter notebooks..................(no files to check)Skipped
Prevent main branch commits..............................................Passed
Check for large files....................................................Passed
Validate pyproject.toml..............................(no files to check)Skipped
Run isort............................................(no files to check)Skipped
pylint (python files in src/)........................(no files to check)Skipped
pylint (test-ish python files).......................(no files to check)Skipped
Run unit tests...........................................................Passed
- hook id: pytest-check
- duration: 4.27s

........................................................................ [ 24%]
........................................................................ [ 48%]
........................................................................ [ 72%]
........................................................................ [ 96%]
...........                                                              [100%]

---------- coverage: platform linux, python 3.10.13-final-0 ----------
Name                                                             Stmts   Miss  Cover   Missing
----------------------------------------------------------------------------------------------
src/hipscat/catalog/association_catalog/association_catalog.py      42      3    93%   71-72, 86
src/hipscat/catalog/healpix_dataset/healpix_dataset.py              53      2    96%   91-92
----------------------------------------------------------------------------------------------
TOTAL                                                             1744      5    99%

50 files skipped due to complete coverage.

Build documentation with Sphinx..........................................Passed

I like it:

  • will show up every time you run pre-commit, even if the tests pass
  • will show the line numbers of uncovered lines, and suppress all other text
  • the individual tests that are passing are shown only as individual dots.

I don't like it:

  • I can't get the dots to go away, but keep the coverage summary

delucchi-cmu avatar Dec 22 '23 20:12 delucchi-cmu

We have codecov in CI actions, so we'll leave this as is for now.

drewoldag avatar Jan 24 '25 19:01 drewoldag