Skip to main content

Show coverage stats online via coveralls.io

Project description

https://img.shields.io/coveralls/coagulant/coveralls-python.svg https://img.shields.io/travis/coagulant/coveralls-python/master.svg https://pypip.in/version/coveralls/badge.svg https://pypip.in/py_versions/coveralls/badge.svg https://pypip.in/download/coveralls/badge.svg

Coveralls.io is service to publish your coverage stats online with a lot of nice features. This package provides seamless integration with coverage.py in your python projects. Only projects hosted on Github are supported.

Usage (Travis CI)

This library will publish your coverage results on coveralls.io for everyone to see (unless you’re using pro account). This package can possibly work with different CI environments, but it’s only tested to work with Travis CI atm.

  1. First, log in via Github and add your repo on Coveralls website.

  2. Add pip install coveralls to install section of .travis.yml

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

  1. Execute run coveralls in after_success section:

    after_success:
      coveralls

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

Usage (another CI)

If you’re NOT using Travis, first option is to provide a repo_token option in .coveralls.yml at the root of your repo. This is your own secret token, which is available at the bottom of your repository’s page on Coveralls. Make sure it stays secret, do not put it in your public repo.

Example of .coveralls.yml:

# .coveralls.yml
repo_token: TjkDuVpGjuQcRhNW8dots9c8SSnv7ReM5

Another alternative is to use COVERALLS_REPO_TOKEN env variable.

Multiple languages (experimental)

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

How it works

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.

Tips for .coveragerc config

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

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.

Troubleshooting

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.

Contributing

Run tests:

$ python setup.py test

Changelog

1.0a1 (2015-02-19)

  • Backwards incompatible: make pyyaml optional. If you’re using .coveralls.yml, make sure to install coveralls[yaml]

  • coverage 4 alpha support

  • Allow debug and output options to work without repo_token

  • Fix merge command for python 3.X

0.5 (2014-12-10)

  • Add option –output=<file> for saving json to file for possible merging with coverages from other languages

  • Add merge command for sending coverage stats from multiple languages

0.4.4 (2014-09-28)

  • Proper fix coverage.py dependency version

0.4.3 (2014-09-28)

  • Fix coverage.py dependency version

0.4.2 (2014-05-05)

  • Handle 503 errors from coveralls.io

0.4.1 (2014-01-15)

  • Fix gitlog output with utf8

0.4 (2013-12-27)

  • Added support for –rcfile=<file> option to cli

  • Improved docs: nosetests and troubleshooting sections added

  • Added debug in case of UnicodeDecodeError

  • Removed sh dependency in favor of Windows compatibility

0.3 (2013-10-02)

  • Added initial support for Circle CI

  • Fixed Unicode not defined error in python 3

0.2 (2013-05-26)

  • Python 3.2 and PyPy support

  • Graceful handling of coverage exceptions

  • Fixed UnicodeDecodeError in json encoding

  • Improved readme

0.1.1 (2013-02-13)

  • Introduced COVERALLS_REPO_TOKEN environment variable as a fallback for Travis

  • Removed repo_token from verbose output for security reasons

0.1 (2013-02-12)

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coveralls-1.0a1.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coveralls-1.0a1-py2.py3-none-any.whl (15.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file coveralls-1.0a1.tar.gz.

File metadata

  • Download URL: coveralls-1.0a1.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for coveralls-1.0a1.tar.gz
Algorithm Hash digest
SHA256 007f502b09fe41e12737f2caf4b4a603af7ad67356ac8dfa7bf65410001fc0cd
MD5 fe2b7660180fa2debd2d77c482d1261a
BLAKE2b-256 766b1d07ee736ce3ac4491a8f284f06ec27018395b0669da602268e97b55f426

See more details on using hashes here.

File details

Details for the file coveralls-1.0a1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for coveralls-1.0a1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f58c3d904c916e6f471d1059ebd9b6c6c1f204489a890eb343448b76c626e76b
MD5 9f3c621a6dd6f710f6fac1b971e56045
BLAKE2b-256 6d0e8a10b4aa2dd76c0b3398474e3371a4b12eec4a74b376b3e30ef0ad9debfa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page