coverage.py

This page contains my notes on coverage.py.

Installation on OS X 10.5

If easy_install coverage fails on OS X and complains about a out-of-date version of setuptools even if you have updated setuptools with sudo easy_install -U setuptools than the problem is that the easy_install script in /usr/bin has the path to the old setuptools package in /System/Library/... hardcoded and won't use the updated version in /Library/Python/....

The error message will look like the following:

The required version of setuptools (>=0.6c9) is not available, and
can't be installed while this script is running. Please install
 a more recent version first, using 'easy_install -U setuptools'.

(Currently using setuptools 0.6c7 (/System/Library/Frameworks/Python.framework/
Versions/2.5/Extras/lib/python))
error: Setup script exited with 2

One simple solution is to use the following command to install coverage:

sudo python -m easy_install coverage

By using the python module directly instead of the script in /usr/bin the updated setuptools version will be used and coverage.py will install happily.

Usage with Django Tests

To get a coverage report for your Django tests just run the following commands:

coverage.py -e
coverage.py -x manage.py test [<appname>]
coverage.py -r -m > coverage.txt