Ratchet up a coverage.py configuration's fail_under to prevent coverage regressions.
Usable with coverage.py directly, or with pytest-cov.
Intended to be run in pre-commit or CI.
If coverage from the last run does not exceed fail_under at all,
coverage run and coverage report will normally fail.
Do nothing in that case.
If code coverage of the last test significantly exceeds fail_under,
recommend increasing the configured fail_under.
Exits with status 1 when changes to configuration should be made.
If --write is passed, also make the changes.
Will not reduce configured fail_under; coverage requirements can only increase.
If fail_under ever reaches 100%, this hook becomes a no-op and can be safely removed.
# .pre-commit-config.yaml
- repo: https://github.com/ellieayla/ratchet-coverage-fail-under
rev: v1.0.3
hooks:
- id: ratchet-coverage
#args: [--write] # whether to automatically write pyproject.toml--cov-config PATH- the configuration file, ideallypyproject.tomlbut defaults to lettingcoverage.pydiscover.--data-file PATH- the .coverage sqlite database file, if necessary to override from configuration file.--threshold PERCENT- recommend a newfail_underthat'sPERCENTof last run. Pass100%to ratchet up to last run exactly.--write- write recommendation back topyproject.toml.