Skip to content

Coverage

Coverage.py is a library bundled with Django that allows a developer to see which parts of the codebase are executed by a test. This can be helpful when writing tests to know how effective your test classes are - and with the right options coverage will tell you exactly which lines are not executed. You are encouraged to familiarise yourself with the coverage docs, which can be found here.

Basic usage

Coverage is only installed onto the attribution-backend repo at this time as it's the only repo that uses Django. You can run coverage locally when testing by using the command coverage run manage.py test. This uses the options found in the coveragerc file to generate a report, which you can then view with coverage report. You can filter down the report to only the files you are interested in by using grep - with a command similar to coverage report | grep {keyword}. Using coverage in this way pinpoints which lines of your code are untested.

Pipelines

We also have a coverage pipeline that will run the coverage report for the entire project. This is separate to our continuous integration pipelines in an attempt to keep those pipelines speedy. The pipeline name is 'Coverage', and you can run the pipeline from here by clicking Run pipeline, choosing a branch and choosing to run the Coverage pipeline