{"id":1162,"library":"diff-cover","title":"Diff-Cover","description":"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.","status":"active","version":"10.2.0","language":"python","source_language":"en","source_url":"https://github.com/Bachmann1234/diff-cover","tags":["testing","coverage","linting","code-quality","git","cli","code-review"],"install":[{"cmd":"pip install diff-cover","lang":"bash","label":"Basic Installation"},{"cmd":"pip install diff-cover[flake8,mypy,pylint,ruff]","lang":"bash","label":"With Common Quality Checkers"}],"dependencies":[{"reason":"Commonly used Python test runner to generate coverage reports, typically in XML format.","package":"coverage.py","optional":false},{"reason":"Pytest plugin for generating coverage reports.","package":"pytest-cov","optional":false},{"reason":"Optional quality checker for Python code.","package":"flake8","optional":true},{"reason":"Optional static type checker for Python.","package":"mypy","optional":true},{"reason":"Optional static code analyzer for Python.","package":"pylint","optional":true},{"reason":"Optional fast Python linter, supports Pylint output format for diff-cover.","package":"ruff","optional":true}],"imports":[],"quickstart":{"code":"git init\n# Create some dummy files and commits for a diff\necho \"def func1():\\n    pass\" > file1.py\ngit add file1.py\ngit commit -m \"Initial commit\"\n\necho \"def func2():\\n    return 1 # new line\" >> file1.py\ngit add file1.py\ngit commit -m \"Add func2\"\n\n# Run your tests with coverage and generate an XML report\n# (Requires pytest-cov and pytest to be installed)\n# For a real project, this would run actual tests\npytest --cov=. --cov-report=xml --ignore=file1.py\n\n# Now, run diff-cover on the generated coverage.xml against the latest diff\n# This example might report 'No lines with coverage information in this diff.'\n# if the dummy coverage report doesn't perfectly align with the diff.\n# In a real scenario, `pytest --cov` would cover the changed lines.\ndiff-cover coverage.xml","lang":"bash","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or newer. If you must use Python 3.9 or older, pin `diff-cover<10.0.0`.","message":"Version 10.1.0 updated the minimum required Python version to `>=3.10`. Version 10.0.0 explicitly dropped support for Python 3.9 while adding support for Python 3.14. Users on older Python versions (e.g., 3.9 or earlier) must upgrade their Python environment or use an older `diff-cover` version.","severity":"breaking","affected_versions":">=10.0.0"},{"fix":"Ensure `diff-cover` is run from the same working directory where the coverage report (e.g., `coverage.xml`) was generated. Verify that file paths in the coverage report align with your Git repository structure. Consider updating to `diff-cover>=10.2.0` for improved subfolder handling.","message":"`diff-cover` relies on source file paths matching exactly between the coverage report and the Git diff. Mismatched relative paths are a common cause of 'No lines with coverage information in this diff.' errors. Version 10.2.0 added support for converting violation paths to relative paths for subfolder support. Version 9.7.2 fixed file name matching on Windows.","severity":"gotcha","affected_versions":"All versions, improved in 9.7.2, 10.2.0"},{"fix":"Use the `--expand-coverage-report` argument (available for XML reports) to add lines not appearing in the coverage report to them, allowing for a more comprehensive diff coverage analysis. Be aware this workaround assumes coverage tools report untested statements with 0 hits.","message":"`diff-cover` may not accurately analyze changes within multi-line statements because coverage reports typically list code statements rather than every changed line. This can lead to lines changed in the diff not being reported in coverage.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review existing configurations for `include` and `exclude` patterns. Update them to either a string or a list of strings, ensuring they work as intended with the new normalized behavior.","message":"In version 10.0.0, the `include` and `exclude` arguments were normalized to accept both a string or a list. While this is generally an improvement, older configurations expecting only one type might behave unexpectedly if not reviewed.","severity":"deprecated","affected_versions":">=10.0.0"},{"fix":"Upgrade to `diff-cover>=9.7.1` to ensure proper compatibility with Ruff, especially with newer versions of Ruff. If unable to upgrade, you might need to configure Ruff to output in a Pylint-compatible format explicitly.","message":"Older versions of `diff-cover` had compatibility issues with Ruff, particularly when Ruff versions >= 0.12.9 were used, requiring a forced Pylint output format. While fixed in v9.7.0 and v9.7.1, users integrating Ruff should be aware.","severity":"gotcha","affected_versions":"<9.7.1"},{"fix":"Install required linting tools manually (e.g., `pip install ruff`) alongside `diff-cover`, as `diff-cover` no longer manages their installation through extras.","message":"`diff-cover` no longer declares optional dependencies (extras) like 'flake8', 'mypy', 'pylint', or 'ruff'. Users expecting to install these dependencies via `pip install diff-cover[extra_name]` will find that these extras are not provided.","severity":"gotcha","affected_versions":">=10.0.0"}],"env_vars":null,"search_vec":"'10.2.0':70 'activ':74 'bump':82 'cadenc':76 'cli':90 'clover':42 'cobertura':41 'code':15,87,92 'code-qu':86 'code-review':91 'command':10 'command-lin':9 'compar':35 'contain':61 'cover':3,6 'coverag':20,38,59,84 'current':67 'depend':81 'diff':2,5,33,52 'diff-cov':1,4 'e.g':40 'enhanc':14 'format':46 'frequent':78 'git':32,51,89 'highlight':54 'issu':63 'jacoco':43 'lack':57 'lcov':45 'librari':65 'line':11,29,55 'lint':22,85 'maintain':72 'modifi':28 'new':26 'output':49 'qualiti':62,88 'releas':75 'report':18,39 'review':16,93 'specif':24 'test':19,58,83 'tool':12 'updat':79 'version':69 'violat':23 'within':30 'xml':37","created_at":"2026-04-05T14:30:47.300950+00:00","updated_at":"2026-04-16T06:24:16.517042+00:00","problems":[{"fix":"Ensure that diff-cover is run from the same working directory where your coverage tool (e.g., coverage.py) generated the XML report, so that file paths in the report align with Git's paths. For multi-module projects, use the `--src-roots` argument to specify the correct base directories for your source code.","cause":"This error occurs when diff-cover cannot match source files in the generated XML coverage report with the files identified in the Git diff, often due to relative path mismatches or incorrect working directories during report generation or diff-cover execution.","error":"No lines with coverage information in this diff."},{"fix":"First, ensure your remote branches are up-to-date by running `git fetch origin`. Then, verify the branch name you are comparing against is correct and exists. You can explicitly specify an existing branch using the `--compare-branch` argument, e.g., `diff-cover coverage.xml --compare-branch=your_base_branch`.","cause":"This error indicates that Git, when invoked by diff-cover, cannot find the specified branch to compare against (e.g., 'origin/main' or 'origin/master'), possibly because the remote branch doesn't exist, hasn't been fetched, or the local repository is in a detached HEAD state.","error":"fatal: ambiguous argument 'origin/main...HEAD': unknown revision or path not in the working tree."},{"fix":"Verify that your test runner is correctly configured to generate a coverage report in a supported XML format and that the path to this report file is correctly passed to the `diff-cover` command. For example, when using `pytest-cov`, generate the report with `pytest --cov --cov-report=xml` and then run `diff-cover coverage.xml`.","cause":"diff-cover requires an XML coverage report (e.g., coverage.xml) in a supported format (Cobertura, Clover, JaCoCo, LCov), and this error indicates that the tool could not locate the specified report file or that the report was empty/malformed.","error":"Error: No XML reports found"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"diff-cover","cli_version":"diff-cover 10.2.0","type":"library","homepage":null,"github":"https://github.com/Bachmann1234/diff-cover","docs":null,"changelog":null,"pypi":"https://pypi.org/project/diff-cover/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-04-11","next_check":"2026-07-04","install_tag":null}}