feat: add --fail-threshold option - #197
Conversation
|
Hi @paveltsialnou, thanks for this, I always appreciate contributions. I'm a bit torn about this PR because it seems to provide a way to return a non-zero exit code for the If the provided metric was the number of uncovered lines instead of the coverage percentage, would that work for you? |
|
@aconrad thanks for sharing your thoughts. I agree that in many cases that approach gives a more stable signal than percentage‑based checks, and your example highlights that well. At the same time, I’ve seen a lot of teams that either aren’t ready to set up historical baselines for diffs or are required by policy to keep overall coverage above a set percentage. The I’m happy to make sure the docs clearly promote uncovered‑lines and diff as the stronger metric for regression prevention, and position percentage as a secondary tool for those who need it. |
With the
Absolutely, agreed.
Let’s walk through a quick example. Say you set In practice, no one wants to wait for coverage to fall that far before getting feedback, right? So the next logical step is to automatically update the baseline whenever coverage changes — for instance, setting the new baseline to the last known 85%. However, when coverage is constantly near the baseline (as happens when you auto-update it), it leads to more false positives — as explained in this paragraph. You might see PRs fail at 84.98% even though there’s no meaningful coverage regression. One possible middle ground could be similar to what you’re suggesting: keeping a "fail under" threshold, but based on the number of uncovered lines instead of a percentage. Whether that threshold is Finally, if coverage moves from 18,426 → 18,449 uncovered lines in a PR, it’s not immediately clear where coverage dropped — maybe a function stopped being called or dead code was introduced. That’s exactly why the So, what do you think about making |
|
This isn’t going to work for me right now, but it might be useful for others. So, is the plan to use |
Correct. That represents uncovered lines. Can you elaborate a little more on how you plan to use pycobertura in your workflow when pycobertura returns a non-zero exit status due to the "fail under" option? Is it for informational purposes only? Or do you expect to take action to fix the coverage check? It would help me understand your use case and maybe spur more ideas. :) |
Yes, since pycobertura relies on an existing report, the stage in which a fix could be applied has already been completed. |
|
@aconrad have you seen the latest update yet? |
There was a problem hiding this comment.
Pull Request Overview
This PR adds a --fail-threshold option to the pycobertura show command that enables returning a non-zero exit code when the total number of uncovered statements exceeds a specified threshold.
- Introduces new exit code
TOTAL_MISSES_ABOVE_THRESHOLD(value 4) for threshold failures - Adds
--fail-thresholdCLI option with minimum value validation (must be >= 1) - Implements exit code logic comparing total misses against the threshold
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| pycobertura/cli.py | Adds new exit code constant, --fail-threshold option definition, and threshold validation logic |
| tests/test_cli.py | Adds comprehensive test coverage for the new option including valid/invalid values and type checking |
| README.md | Documents usage example for the new --fail-threshold option |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Alexandre Conrad-Dormoy <alexandre.conrad@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Thanks for this. Can you add an entry in the CHANGES file please, under the "Unreleased" paragraph (follow other release note examples for formatting) |
Add `--fail-threshold` option to return non-zero exit code for uncovered lines exceeding threshold.
Add new
--fail-underoption that allows to return non-zero exit code whenpycobertura show cobertura.xmlis used.