Setup Coveralls.io automatic code coverage tests

Related: Travis-CI examples


.travis.yml code coverage tests using coveralls.io are a nice way to track code coverage. The one-time setup is very similar to Travis-CI, and assumes you have a free coveralls.io account–using your Github credentials and have added the Git repository to Coveralls.

The pytest-cov module is excellent for recursively testing coverage. Create file .coveragerc like:

[run]
cover_pylib = false
omit =
  /home/travis/virtualenv/*
  */site-packages/*
  */bin/*

[report]
exclude_lines =
  pragma: no cover
  def __repr__
  RuntimeError
  NotImplementedError
  FileNotFoundError
  ImportError

.travis.yml must have a line like

after_success:
  - pytest --cov

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.