From 9f29efdf20c5dcfe49e85cc61c0839730be2462e Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Sun, 23 Dec 2018 20:19:39 -0500 Subject: [PATCH] Disallow impossible values for fail_under Since there's no way were likely to achieve greater than 100% code coverage, disallow usage of any value above 100. Resolves #743 Signed-off-by: Mike Fiedler --- CONTRIBUTORS.txt | 1 + coverage/results.py | 4 ++++ tests/test_results.py | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 4c07024c0..93f271538 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -81,6 +81,7 @@ Matthew Desmarais Max Linke MichaƂ Bultrowicz Mickie Betz +Mike Fiedler Nathan Land Noel O'Boyle Olivier Grisel diff --git a/coverage/results.py b/coverage/results.py index cab8796e2..9be16b15e 100644 --- a/coverage/results.py +++ b/coverage/results.py @@ -283,6 +283,10 @@ def should_fail_under(total, fail_under, precision): Returns True if the total should fail. """ + # We can never achieve higher than 100% coverage + if fail_under > 100.0: + raise ValueError("`fail_under` is greater than 100. Please use 100 or lower.") + # Special case for fail_under=100, it must really be 100. if fail_under == 100.0 and total != 100.0: return True diff --git a/tests/test_results.py b/tests/test_results.py index 307ef7623..f83b73dd8 100644 --- a/tests/test_results.py +++ b/tests/test_results.py @@ -105,3 +105,8 @@ def test_covered_ratio(self): ]) def test_should_fail_under(total, fail_under, precision, result): assert should_fail_under(float(total), float(fail_under), precision) == result + + +def test_should_fail_under_invalid_value(): + with pytest.raises(ValueError): + should_fail_under(100.0, 101, 0)