Show coverage stats online via coveralls.io
It makes custom report for data generated by coverage.py package and sends it to json API of coveralls.io service. All python files in your coverage analysis are posted to this service along with coverage stats, so please make sure you’re not ruining your own security! For private projects there is Coveralls Pro.
This package works with any CI environments. Instructions for Travis CI:
Log in and add your repo on Coveralls website.
Add pip install coveralls to install section of .travis.yml
Make sure you run your tests with coverage during the build in script part. Example:
# --source specifies what packages to cover, you probably want to use that option script: coverage run --source=yourpackagename setup.py test
Note, that example command will gather coverage for specified package. If you wish to customize what’s included in your reports, consult coverage docs.
Execute run coveralls in after_success section:
Full example of .travis.yml:
language: python python: - 2.7 - 3.3 install: - pip install -r requirements.txt - pip install coveralls script: coverage run --source=moscowdjango,meetup manage.py test after_success: coveralls
Pass the environment variables TRAVIS, TRAVIS_JOB_ID, TRAVIS_BRANCH to all tox environments that submit the coverage report.
Example of tox.ini:
[tox] envlist = py27,py33,py34 [testenv] passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH deps = coveralls commands = coverage run --source=yourpackagename setup.py test coveralls
Circle CI users should pass CIRCLE_BRANCH, Codeship users - CI_BRANCH.
The difference from Travis is coveralls authentication via repo token. Circle CI is supported since version 1.1, so no need to add env variables. It’s required to set environment variable COVERALLS_REPO_TOKEN in you CI build. This is your own secret token, which is available at the right sidebar of your repository’s page on Coveralls. Launch coveralls after gathering python coverage in your build script.
coverage run --source=myapp setup.py test COVERALLS_REPO_TOKEN=tGSdG5Qcd2dcQa2oQN9GlJkL50wFZPv1j coveralls
Tracking multi-language repo coverage requires extra setup of merging coverage data for submission. If you already have json file from coveralls library from another language (example from coveralls-lcov):
# Generate data with lcov lcov --compat-libtool --directory . --capture --output-file coverage.info # Or: generate data with mocha mocha --reporter mocha-lcov-reporter */tests/static/js/* > coverage.info # Convert data with coveralls-lcov coveralls-lcov -v -n coverage.info > coverage.json # Merge python coverage with coveralls-style json file and send it to api endpoint # Note: This file must contain "source_files" data or it will not be merged coveralls --merge=coverage.json
If you’d like to just use json data from coveralls (with other tools):
coveralls --output=coverage.json # output single json with python coverage in coveralls format
This section is a list of most common options for coverage.py, which collects all the data. Coveralls feeds from this data, so it’s good to know how to to configure coverage.py.
To limit the report with only your packages, specify their names (or directories):
[run] source = pkgname,your_otherpackage
To exclude parts of your source from coverage, for example migrations folders:
[report] omit = */migrations/*
Some lines are never executed in your tests, but that can be ok. To mark those lines use inline comments right in your source code:
if debug: # pragma: no cover msg = "blah blah" log_message(msg, a)
Sometimes it can be tedious to mark them in code, so you can specify whole lines to .coveragerc:
[report] exclude_lines = pragma: no cover def __repr__ raise AssertionError raise NotImplementedError if __name__ == .__main__.:
Finally, if you’re using non-default configuration file, specify it to coveralls command:
$ coveralls --rcfile=<file>
Nosetests provide a plugin for coverage measurement of your code:
$ nosetests --with-coverage --cover-package=<your_package_name>
However, it gathers coverage for all executed code, ignoring source config option in .coveragerc. It means, that coveralls will report unnecessary files, which is inconvenient. Here is a workaround, use omit option in your .coveragerc to specify a list of filename patterns, the files to leave out of reporting (your paths might differ)
[report] omit = */python?.?/* */site-packages/nose/*
Note, that native coverage.py and py.test are not affected by this problem and do not require this workaround.
In case your coverage is not submitted to coveralls.io, despite your best efforts to configure, you can use debug:
$ coveralls debug
Debug mode doesn’t send anything, just outputs prepared json and reported files list to stdout.
$ python setup.py test
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|coveralls-1.1-py2.py3-none-any.whl (15.9 kB) Copy SHA256 Checksum SHA256||py2.py3||Wheel||Oct 19, 2015|
|coveralls-1.1.tar.gz (12.1 kB) Copy SHA256 Checksum SHA256||–||Source||Oct 19, 2015|