Diff-Cover

10.2.0 · active · verified Sun Apr 05

Diff-Cover is a command-line tool that enhances code review by reporting test coverage and linting violations specifically on new or modified lines within a Git diff. It compares an XML coverage report (e.g., Cobertura, Clover, JaCoCo, or LCov format) with the output of `git diff` to highlight lines that lack test coverage or contain quality issues. The library is currently at version 10.2.0 and maintains an active release cadence with frequent updates and dependency bumps.

Warnings

Install

Quickstart

This quickstart demonstrates the core functionality of `diff-cover`. First, ensure you have a Git repository and a `coverage.xml` report generated by a tool like `coverage.py` or `pytest-cov`. The `diff-cover` command then compares this report against your Git changes to identify uncovered or problematic lines in the diff.

git init
# Create some dummy files and commits for a diff
echo "def func1():\n    pass" > file1.py
git add file1.py
git commit -m "Initial commit"

echo "def func2():\n    return 1 # new line" >> file1.py
git add file1.py
git commit -m "Add func2"

# Run your tests with coverage and generate an XML report
# (Requires pytest-cov and pytest to be installed)
# For a real project, this would run actual tests
pytest --cov=. --cov-report=xml --ignore=file1.py

# Now, run diff-cover on the generated coverage.xml against the latest diff
# This example might report 'No lines with coverage information in this diff.'
# if the dummy coverage report doesn't perfectly align with the diff.
# In a real scenario, `pytest --cov` would cover the changed lines.
diff-cover coverage.xml

view raw JSON →