Django Code Coverage

April 19, 2019

I have a Django application with tests, and I wanted to see what my code coverage was when those tests are run. This is fairly straightforward.

First, install coverage:

$ pip install coverage

Then, instead of running python test, run the following in the same directory:

$ coverage run --source='.' test

To get a nice HTML report of coverage in a subdirectory, run

$ coverage html