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:

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

Then in .travis.yml 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.

Tags: ,

Categories:

Written by Michael Hirsch, Ph.D. //

Comments