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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file fun_coverage-0.2.0.tar.gz.

File metadata

  • Download URL: fun_coverage-0.2.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for fun_coverage-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5a77f8ca857bf991f9d4b76504ccee93aecea89153490f31d5d8c1c1d22e3e24
MD5 2e618ce3f2346532273b55c3f228b401
BLAKE2b-256 cf7bac57f35158c1060a808b5c120238936508b17d8aec9e2706dc92e997191c

See more details on using hashes here.

File details

Details for the file fun_coverage-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fun_coverage-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 292d355a974f8f500b29dbe02a7b4a591516c670cb3a0c9cd68fe034978bddad
MD5 37bd829b1fe0b56b6aba1705519c0c7f
BLAKE2b-256 ea7d707a65cb26a6ac7b905b615d6c4d973826e39b985156488f922bcc9745c6

See more details on using hashes here.

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