Skip to main content

Show coverage stats online via coveralls.io

Project description

Coveralls for python
====================

.. image:: https://travis-ci.org/coagulant/coveralls-python.png?branch=master
:target: https://travis-ci.org/coagulant/coveralls-python

.. image:: https://coveralls.io/repos/coagulant/coveralls-python/badge.png?branch=master
:target: https://coveralls.io/r/coagulant/coveralls-python

.. image:: https://pypip.in/v/coveralls/badge.png
:target: https://crate.io/packages/coveralls/

`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.
For ruby projects, there is an `official gem`_.
Only projects hosted on Github are supported.

Works with python 2.6+, 3.2+ and pypy 1.9.

.. _Coveralls.io: http://coveralls.io
.. _nice features: https://coveralls.io/info/features
.. _official gem: https://coveralls.io/docs/ruby

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

.. _coverage docs: http://nedbatchelder.com/code/coverage/

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

.. _add your repo: https://coveralls.io/repos/new
.. _Travis CI: http://travis-ci.org


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 ``.coverage.rc``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.

.. _Nosetests:http://nose.readthedocs.org/en/latest/plugins/cover.html

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

.. _json API: https://coveralls.io/docs/api_reference
.. _Coveralls Pro: https://coveralls.io/docs/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>

.. _how to to configure coverage.py: http://nedbatchelder.com/code/coverage/config.html
.. _report with only your packages: http://nedbatchelder.com/code/coverage/source.html#source
.. _specify whole lines to .coveragerc: http://nedbatchelder.com/code/coverage/excluding.html

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

Install latest `unstable version`_::

$ pip install coveralls==dev

.. _unstable version: https://github.com/coagulant/coveralls-python/archive/master.zip#egg=coveralls-dev


.. image:: https://d2weczhvl823v0.cloudfront.net/coagulant/coveralls-python/trend.png
:alt: Bitdeli badge
:target: https://bitdeli.com/free



Changelog
---------

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-0.4.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

coveralls-0.4-py2.py3-none-any.whl (13.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file coveralls-0.4.tar.gz.

File metadata

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

File hashes

Hashes for coveralls-0.4.tar.gz
Algorithm Hash digest
SHA256 b2e40694bf227e65b42127245b5ec205f4174be55d88d62b4c0211fe1196a636
MD5 a3a2caf7de595abb62164070471551a9
BLAKE2b-256 856e0cdd8df8bb2a989937646f333a5865b31377ab5f735ea925f993d536eec1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for coveralls-0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1125b5f244618851c99d16ef28199bc828dffad4d8539622a9770af3655de6ea
MD5 c2e6f91497f5654d37a9ccf055cb1dd2
BLAKE2b-256 1703443d0fdd3e2804b873465ecd21451a901aac7d685aba4a9ddd2794c11ee3

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