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–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:

[coverage:run]
cover_pylib = false
omit =
  /home/travis/virtualenv/*
  */site-packages/*
  */bin/*
    
[coverage:report]
exclude_lines =
  pragma: no cover
  def __repr__
  RuntimeError
  NotImplementedError
  FileNotFoundError
  ImportError

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.

Leave a comment