Skip to content

Commit d5c3daa

Browse files
committed
fix: an empty file shouldn't fail with --fail-under=99. #1470
1 parent e5a15c1 commit d5c3daa

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ Unreleased
2929
- Using ``--format=total`` will write a single total number to the
3030
output. This can be useful for making badges or writing status updates.
3131

32+
- An empty file has a coverage total of 100%, but used to fail with
33+
``--fail-under``. This has been fixed, closing `issue 1470`_.
34+
3235
- Fixed a mis-measurement of a strange use of wildcard alternatives in
3336
match/case statements, closing `issue 1421`_.
3437

3538
.. _pull 1479: https://github.com/nedbat/coveragepy/pull/1479
3639
.. _issue 1418: https://github.com/nedbat/coveragepy/issues/1418
3740
.. _issue 1421: https://github.com/nedbat/coveragepy/issues/1421
41+
.. _issue 1470: https://github.com/nedbat/coveragepy/issues/1470
3842

3943

4044
.. _changes_6-6-0b1:

coverage/summary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def report(self, morfs, outfile=None):
165165
else:
166166
self.tabular_report()
167167

168-
return self.total.n_statements and self.total.pc_covered
168+
return self.total.pc_covered
169169

170170
def tabular_report(self):
171171
"""Writes tabular report formats."""

tests/test_process.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,8 @@ def test_report(self):
10931093
st, _ = self.run_command_status("coverage run empty.py")
10941094
assert st == 0
10951095
st, _ = self.run_command_status("coverage report")
1096-
assert st == 2
1096+
# An empty file is marked as 100% covered, so this is ok.
1097+
assert st == 0
10971098

10981099

10991100
@pytest.mark.skipif(env.WINDOWS, reason="Windows can't delete the directory in use.")

0 commit comments

Comments
 (0)