Fail --fail-under=100 when a docstring is missing - #192
Conversation
_get_coverage rounds the coverage percentage to the number of decimals given on --fail-under before comparing. With 2,000 nodes and a single missing docstring, 99.95% rounds up to 100.0 and the run passes, which is the opposite of what --fail-under=100 asks for. Keep the rounded value for the comparison, except when nodes are actually missing and rounding has reached 100 - then compare against the exact percentage. Fixes econchick#186
4d65896 to
609b2b3
Compare
|
Both red checks here are pre-existing, and I can show that for each. Read the Docs fails on every open pull request in this repository, including ones I have nothing to do with — #188, #189 and #190 all carry the same failed build. pre-commit.ci fails in the The pinned On my side the hooks are clean at their pinned versions. Running each id from
Test suite: 231 passed, 13 skipped, 0 failed — the baseline is 228 passed, 13 skipped, 0 failed. |
|
Closing this as a duplicate of #193, which carries the same change and the same test. Both were opened within seconds of each other on my side, which should not have happened — apologies for the noise. #193 is the one to review. Its description also gets the root cause right, where this one does not: For what it is worth on the red checks here: |
Fixes #186.
_get_coveragerounds the coverage percentage to the number of decimals given on--fail-under, then compares:--fail-under=100has no decimals, soround_tois 0 and the percentage is rounded to a whole number. Once a codebase is large enough that one missing docstring is worth less than half a percent, the rounded value reaches 100 and the run passes:The fix keeps the rounded value for the comparison, except when nodes are actually missing and rounding has reached 100 — then the exact percentage is used. Nothing else changes: rounding still works as intended for
--fail-under=95.5, and a genuinely complete codebase still passes.One correction to the issue title
The threshold is 2,000 nodes, not 4,000 functions. Rounding flips at 99.5% for
--fail-under=100, andinterrogatecounts modules and classes as nodes alongside functions, so the false pass starts at 1 missing docstring out of 2,000 nodes. I've written the test at exactly that boundary.Measured
python -m pytestonf35a9d6:missing=1 total=2000 perc=99.95 ret=0The new test is parametrised over three cases: 1999/2000 with one missing docstring (the report), 1999/2000 complete (must still pass), and 10 functions with one missing (the small-codebase path that already worked).
Project hooks from
.pre-commit-config.yamlat their pinned versions:black24.3.0,isort,flake8,mypyandinterrogateon itself are all clean. Note that a newerblackwants to reformat the import block ofcoverage.py, but it does that on an untouched checkout too — it's a version drift, not this change, and I left it alone.docs/changelog.rstgains aFixedentry under1.8.0 (UNRELEASED).AI-assisted (LLM used for drafting); the runs above are mine.