Skip to content

Commit

Permalink
Disallow impossible values for fail_under
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
miketheman authored and nedbat committed Dec 24, 2018
1 parent ce9194a commit 9f29efd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Matthew Desmarais
Max Linke
Michał Bultrowicz
Mickie Betz
Mike Fiedler
Nathan Land
Noel O'Boyle
Olivier Grisel
Expand Down
4 changes: 4 additions & 0 deletions coverage/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 9f29efd

Please sign in to comment.