Skip to main content

pycobertura

A Cobertura coverage parser that can diff reports.

Travis PyPI

Features:

  • show coverage summary of a cobertura file

  • diff two cobertura files and show relative progress

  • output in plain text or HTML

  • colorized diff output

Install

$ pip install pycobertura

CLI usage

pycobertura provides a command line interface to report on coverage files.

$ pycobertura --help

The show command displays the report summary of a coverage file.

$ pycobertura show coverage.xml
Name                     Stmts    Miss  Cover    Missing
---------------------  -------  ------  -------  ---------
pycobertura/__init__         1       0  100.00%
pycobertura/cli             18       0  100.00%
pycobertura/cobertura       93       0  100.00%
pycobertura/reports        129       0  100.00%
pycobertura/utils           12       0  100.00%
TOTAL                      253       0  100.00%

You can also use the diff command to show the difference between two coverage files.

$ pycobertura diff coverage.old.xml coverage.new.xml
Name          Stmts    Miss    Cover     Missing
------------  -------  ------  --------  ---------
dummy/dummy   -        -2      +50.00%   -2, -5
dummy/dummy2  +2       -       +100.00%
TOTAL         +2       -2      +50.00%

The column Missing will show line numbers prefixed with either a plus sign + or a minus sign -. When prefixed with a plus sign, the line was introduced as uncovered, when prefixed as a minus sign, the line is no longer uncovered.

Library usage

Using it as a library in your Python application is easy:

from pycobertura import Cobertura
cobertura = Cobertura('coverage.xml')

cobertura.version == '3.7.1'
cobertura.line_rate() == 1.0  # 100%
cobertura.classes() == [
    'pycobertura/__init__',
    'pycobertura/cli',
    'pycobertura/cobertura',
    'pycobertura/reports',
    'pycobertura/utils',
]
cobertura.line_rate('pycobertura/cli') == 1.0

from pycobertura import TextReporter
tr = TextReporter(cobertura)
tr.generate() == """\
Name                     Stmts    Miss  Cover    Missing
---------------------  -------  ------  -------  ---------
pycobertura/__init__         1       0  100.00%
pycobertura/cli             18       0  100.00%
pycobertura/cobertura       93       0  100.00%
pycobertura/reports        129       0  100.00%
pycobertura/utils           12       0  100.00%
TOTAL                      253       0  100.00%"""

from pycobertura import TextReporterDelta

coverage1 = Cobertura('coverage1.xml')
coverage2 = Cobertura('coverage2.xml')
delta = TextReporterDelta(coverage1, coverage2)
delta.generate() == """\
Name          Stmts    Miss    Cover     Missing
------------  -------  ------  --------  ---------
dummy/dummy   -        -2      +50.00%   -2, -5
dummy/dummy2  +2       -       +100.00%
TOTAL         +2       -2      +50.00%"""

Contribute

Found a bug? Got a patch? Have an idea? Please use Github issues or fork pycobertura and submit a pull request (PR). All contributions are welcome!

If you submit a PR:

  • ensure the description of your PR illustrates your changes clearly by showing what the problem was and how you fixed it (before/after)

  • make sure your changes are covered with one or more tests

  • add a descriptive note in the CHANGES file under the Unreleased section

  • update the README accordingly if your changes outdate the documentation

  • make sure all tests are passing using tox

pip install tox
tox

Release Notes

Unreleased

0.3.0 (2014-12-23)

  • update description of pycobertura

  • pep8-ify

  • add pep8 tasks for tox and travis

  • diff command returns non-zero exit code if coverage worsened

  • Cobertura.branch_rate is now a method that can take an optional class_name argument

  • refactor internals for improved readability

  • show classes that contain no lines, e.g. __init__.py

  • add Cobertura.filename(class_name) to retrieve the filename of a class

  • fix erroneous reporting of missing lines which was equal to the number of missed statements (wrong because of multiline statements)

0.2.1 (2014-12-10)

  • fix py26 compatibility by switching the XML parser to lxml which has a more predictible behavior when used across all Python versions.

  • add Travis CI

0.2.0 (2014-12-10)

  • apply Skeleton 2.0 theme to html output

  • add -o / --output option to write reports to a file.

  • known issue: diffing 2 files with options --format text, --color and --output does not render color under PY2.

0.1.0 (2014-12-03)

  • add --color and --no-color options to pycobertura diff.

  • add option -f and --format with output of text (default) and html.

  • change class naming from report to reporter

0.0.2 (2014-11-27)

  • MIT license

  • use pypandoc to convert the long_description in setup.py from Markdown to reStructuredText so pypi can digest and format the pycobertura page properly.

0.0.1 (2014-11-24)

  • Initial version

Metadata

Release files for pycobertura 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycobertura 0.3.0
File Size Uploaded
pycobertura-0.3.0.tar.gz 23.7 kB Details

Release files / pycobertura-0.3.0.tar.gz

Download URL pycobertura-0.3.0.tar.gz
Size 23.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a14ef21f251bcbcd0940945ff44281dedc85ce70bf8ae1e64f4f89069b1a8267
BLAKE2b-256 checksum
How to use checksums
f8282166ef93b19742b9979396447bed69d477aacf102b45b80fd3f5e6d99563
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

4.1.0

2 release files

4.0.0

2 release files

3.3.2

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.2.4

2 release files

3.2.3

2 release files

3.2.2

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.1.0

1 release file

2.0.1

1 release file

2.0.0

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.10.5

1 release file

0.10.4

1 release file

0.10.3

1 release file

0.10.2

1 release file

0.10.1

1 release file

0.10.0

1 release file

0.9.0

1 release file

0.8.0

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.1

1 release file

0.4.0

1 release file

This release

0.3.0 This release

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page