Setup automatic code coverage tests

Related: Travis-CI examples

At the bottom of most of my .travis.yml are code coverage tests using The one-time setup is very similar to Travis-CI:

  1. Create a free account–using your Github credentials.
  2. add a repository to Coveralls

The pytest-cov module is excellent for recursively testing coverage. You do NOT need .coveragerc, instead configure with setup.cfg, with content like:

cover_pylib = false
omit =
exclude_lines =
  pragma: no cover
  def __repr__

Coverage on own computer

To help debug coverage issues, simply do the coverage test on your own computer, from Terminal:

pytest --cov --cov-report html

firefox htmlcov/index.html

and then you can browse a color-highlighted version of each of your files, showing which lines were excluded, covered or not covered.

Tags: ,


Written by Michael Hirsch, Ph.D. //