pytest-cover

3.0.0 · abandoned · verified Wed Apr 15

pytest-cover is a pytest plugin for measuring code coverage, which was forked from pytest-cov. The project was officially merged back into pytest-cov in January 2019, and its GitHub repository explicitly states to use pytest-cov instead. This library (version 3.0.0) is effectively abandoned and users are strongly advised to use the actively maintained `pytest-cov` for coverage reporting with pytest.

Warnings

Install

Quickstart

Since `pytest-cover` is abandoned, the quickstart illustrates usage for its successor, `pytest-cov`. It involves creating a simple Python module and a corresponding test file. The plugin integrates directly with `pytest` via command-line options. Running `pytest --cov=your_module` will execute tests and show a coverage report in the terminal. You can also generate an HTML report with `--cov-report=html`.

# This quickstart is for the recommended alternative: pytest-cov
# Install required packages: pip install pytest pytest-cov

# my_module.py
def my_function(x):
    if x > 0:
        return x * 2
    else:
        return 0

# test_my_module.py
from my_module import my_function

def test_positive_input():
    assert my_function(5) == 10

def test_zero_input():
    assert my_function(0) == 0

def test_negative_input():
    assert my_function(-3) == 0

# To run tests and generate a coverage report (terminal output):
# pytest --cov=my_module

# To generate an HTML report:
# pytest --cov=my_module --cov-report=html

# Example of running the command (execute in your terminal where files are saved):
# import os
# os.system('pytest --cov=my_module')
# os.system('pytest --cov=my_module --cov-report=html')

view raw JSON →