Skip to main content
Build Release
Build#develop PyPI version

Overview

This plugin attempts to provide a more meaningful test coverage metric for projects using pytest. The assumption is that, in reality, the proportion of lines of code covered by tests does not entirely reflect how much the tests explicitly cover. An additional indicator is how many functions, out of the total functions defined in a project, are explicitly invoked during tests. This way, a test which only calls a higher order function will not also count as testing the functions that it invokes during its execution, unlike traditional test coverage metrics.

pytest_func_cov provides an implementation of this metric, covering functions as well as methods, classmethods and staticmethods. A function is considered tested if it is invoked explicitly from a test function at least once. To make this check, the second stack frame is inspected when a discovered function is invoked.

Usage

pytest --func_cov=myproject tests/

Produces a report like:

--------------------pytest_func_cov-----------
Name                   Funcs   Miss     Cover
----------------------------------------------
myproject/module1.py       7      5       28% 
myproject/module2.py      10      3       70%
----------------------------------------------
TOTAL                     17      8       47%   

Similar to pytest-cov, you can use the --func_cov_report argument to configure the output. At the moment, the only supported option is term-missing, which adds another column to the output which lists all untested functions.

pytest --func_cov=myproject --func_cov_report=term-missing tests/

Produces a report like:

--------------------pytest_func_cov--------------------
Name                   Funcs   Miss     Cover   Missing
-------------------------------------------------------
myproject/module1.py       7      5       28%   func1, func2, MyClass.method, MyClass.static_method, MyClass.class_method
myproject/module2.py      10      3       70%   func3, func4, <lambda>
-------------------------------------------------------
TOTAL                     17      8       47%   

Configuration

A list of function name patterns to ignore can be specified in pytest.ini.

Example:

[pytest]
ignore_func_names = 
    ^test_*
    ^myfunction$

This will ignore all function names starting with "test_" and functions named "myfunction".

Release files for pytest-func-cov 0.2.3

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

Source distribution (sdist)

Source distribution for pytest-func-cov 0.2.3
File Size Uploaded
pytest_func_cov-0.2.3.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-func-cov 0.2.3
File Interpreter ABI Platform
pytest_func_cov-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / pytest_func_cov-0.2.3.tar.gz

Download URL pytest_func_cov-0.2.3.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
241993f9523b7d8921a6b03e937491c2190ce4bf2b314a328ed8e10c1713bd25
BLAKE2b-256 checksum
How to use checksums
38ca34becca16cfa83be6b7aa8c80319c569225a1758f929048ca1c93ffcd859
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.13

Release files / pytest_func_cov-0.2.3-py3-none-any.whl

Download URL pytest_func_cov-0.2.3-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d43da4463318ed12afe9a9e22cb858709b93947166f6a4319902dd745cc5dd2
BLAKE2b-256 checksum
How to use checksums
e3f3cb1ed7d54d11c68d4e1d6c266847c88bbbe631b319401b6e4ab3828358dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.13

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

1 release file

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