Skip to content

Commit 4371697

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

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
@@ -25,12 +25,16 @@ Unreleased
2525
use ``--format=markdown`` to get the table in Markdown format, thanks to
2626
Steve Oswald in `pull 1479`_, closing `issue 1418`_.
2727

28+
- An empty file has a coverage total of 100%, but used to fail with
29+
``--fail-under``. This has been fixed, closing `issue 1470`_.
30+
2831
- Fixed a mis-measurement of a strange use of wildcard alternatives in
2932
match/case statements, closing `issue 1421`_.
3033

3134
.. _pull 1479: https://github.com/nedbat/coveragepy/pull/1479
3235
.. _issue 1418: https://github.com/nedbat/coveragepy/issues/1418
3336
.. _issue 1421: https://github.com/nedbat/coveragepy/issues/1421
37+
.. _issue 1470: https://github.com/nedbat/coveragepy/issues/1470
3438

3539

3640
.. _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)