Setup Coveralls.io automatic code coverage tests

less than 1 minute read

Related: Travis-CI examples


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

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

You can have custom directories/patterns omitted from the coverage test.

.coveragerc

My repos’ .coveragerc file something like:

[run]
cover_pylib = false
omit =
    /home/travis/virtualenv/*
    
[report]
exclude_lines =
    pragma: no cover
    def __repr__
    RuntimeError
    NotImplementedError
    ImportError

Coverage on own computer

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

coverage run tests/test_all.py

coverage 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.

Notes

Some of my Travis-CI repos have recently seen a bug where .coveragerc is ignoring default:

[run]
cover_pylib=false

and thus does coverage on the system Python libraries! This is not desired behavior.

Leave a Comment