Skip to main content

Report function-level code coverage from the statement-level coverage of coverage.py

Project description

fun-coverage

fun-coverage is a tool to extract function coverage from the statement (= line) coverage of coverage.py.

Installation

The simplest way to install fun-coverage is with pip:

pip install fun-coverage

Getting started

After installing the package, a fun-coverage command will be available.

You need to run coverage.py first. For example, if you're using it through pytest-cov:

pytest --cov=<my_module> <my_module_tests>

Once this is done, simply run:

fun-coverage

This will print a text report similar to the one of coverage.py, but for functions. The report will include the line numbers of the missed functions.

For example, this is the output of fun-coverage run on its example test suite (as a preliminary step of its actual test suite):

Name                                                                            Funcs   Miss   Cover   Missing
--------------------------------------------------------------------------------------------------------------
tests/example_test_suite/src/__init__.py                                            0      0    100%
tests/example_test_suite/src/async_function.py                                      1      0    100%
tests/example_test_suite/src/covered_function_with_partially_covered_lines.py       1      0    100%
tests/example_test_suite/src/docstring_only_function.py                             1      0    100%
tests/example_test_suite/src/excluded_function.py                                   0      0    100%
tests/example_test_suite/src/methods.py                                             2      2      0%   6, 9
tests/example_test_suite/src/non_covered_function.py                                1      1      0%   1
--------------------------------------------------------------------------------------------------------------
TOTAL                                                                               6      3     50%

How it works

fun-coverage looks for functions and methods in the source code files concerned by a previous round of statement coverage measurement, then marks them as hit if and only if their first statement has been hit.

Specifically, this starts from the .coverage file left by coverage.py. This is configurable with the --cov-file flag.

Command-line options

usage: fun-coverage [--cov-file COV_FILE] [--cov-fail-under MIN]

  --cov-file COV_FILE   Which coverage file to analyze (default .coverage in the current directory)
  --cov-fail-under MIN  Fail if the total coverage is strictly less than MIN (a percentage between 0 and 100)

Excluding code from fun-coverage

If the line containing the def or async def statement for a function is excluded from coverage.py, then fun-coverage ignores that entire function.

Compatibility

fun-coverage has been tested with coverage==6.4, and pytest-cov==3.0.0.

Development

This section only applies if you wish to contribute to the project.

pre-commit

This project uses pre-commit. Please install it, then activate it to run automatically on git commit:

pre-commit install

Tests

Run the test suite with:

make test

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

fun_coverage-0.2.0.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

fun_coverage-0.2.0-py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 3

Supported by

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