diff options
author | Mike Fiedler <miketheman@gmail.com> | 2018-12-23 20:19:39 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2018-12-23 22:13:53 -0500 |
commit | 9f29efdf20c5dcfe49e85cc61c0839730be2462e (patch) | |
tree | 9e9d9ed3d9db32f2b64488ac68b07d13bd84111f | |
parent | ce9194abe4c369c455cca9f1d88c25b70db031e6 (diff) | |
download | python-coveragepy-git-9f29efdf20c5dcfe49e85cc61c0839730be2462e.tar.gz |
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 <miketheman@gmail.com>
-rw-r--r-- | CONTRIBUTORS.txt | 1 | ||||
-rw-r--r-- | coverage/results.py | 4 | ||||
-rw-r--r-- | tests/test_results.py | 5 |
3 files changed, 10 insertions, 0 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 4c07024c..93f27153 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 cab8796e..9be16b15 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 307ef762..f83b73dd 100644 --- a/tests/test_results.py +++ b/tests/test_results.py @@ -105,3 +105,8 @@ class NumbersTest(CoverageTest): ]) 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) |