Skip to main content

Pytest Plugin to Show Unit Coverage

Code coverage tools like coverage.py show you the instrumented code coverage of your tests, however it won't tell you if you've written specific unit tests for each of your code's units (here unit meaning function).

This package implements a mechanism for measuring and reporting unit coverage. Instead of instrumenting your code you will need to mark tests with a pointer to the unit that it is covering.

For example if you have in your code this module mypackage/widget.py:

def foo(in):
    return in * 3

then in your test suite you would write a unit test for this function and mark it as relating to that unit, e.g. in tests/test_widget.py:

from mypackage.widget import foo

@pytest.mark.pointer(foo)
def test_foo():
    assert foo(3) == 9

This package works by collecting all of the pointed-to units during test execution and persists these to the pytest cache (typically somewhere under .pytest_cache). Then in subsequent runs you need only report the results.

Invocation

This package adds a couple new options to the pytest CLI:

--pointers-collect=STR (default src)

This explicitly indicates to collect unit coverage results. If not specified, but --pointers-report is given results will be collected using the default.

--pointers-report (default False)

When this flag is given a textual report will be given at the end of the test run. Note that even if this is not given the coverage checks will still be run.

--pointers-func-min-pass=INT (default 2)

This flag controls the number of unit test pointer marks are needed to get a "passing" unit. In the report units with 0 pointers are shown as red, passing numbers are green, and anything in between is blue.

--pointers-fail-under=FLOAT (default 0.0)

This flag controls the percentage of passing units are needed for the entire coverage check to pass. The percentage is always displayed even without --pointers-report. If this test is failed then the test process exits with code 1, which is useful for things like CI.

Example

Here is an example with source code under the src folder, requiring 1 pointer test per collected unit in the code, for all functions.

pytest --pointers-report --pointers-collect=src --pointers-func-min-pass=1 --pointers-fail-under=100 tests

Installation

pip install pytest_pointers

Release files for pytest-pointers 0.3.1

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-pointers 0.3.1
File Size Uploaded
pytest-pointers-0.3.1.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-pointers 0.3.1
File Interpreter ABI Platform
pytest_pointers-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.2 kB

Release files / pytest-pointers-0.3.1.tar.gz

Download URL pytest-pointers-0.3.1.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1fd3ad896ce344bbac58c32b4fffda6533f84869e6d2b1b4049a92a3184d71c4
BLAKE2b-256 checksum
How to use checksums
08f1d87614d1dd90394ac66a938aca7b4dd19f6b29a9bc47f44726fe11fe6bf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.16 Linux/5.15.0-1024-azure

Release files / pytest_pointers-0.3.1-py3-none-any.whl

Download URL pytest_pointers-0.3.1-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27d37ccd2b78862805142c693e39e43a1b4dbb12b8e4ef9b9baaad599dc10aba
BLAKE2b-256 checksum
How to use checksums
e4ef73d1bec20a39a5b519fe1bcc3a2797dc10b31ea2701c9260bf9d294bd55c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.16 Linux/5.15.0-1024-azure

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.7

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.0.1

2 release files

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