Skip to content

Commit

Permalink
fix: an empty file shouldn't fail with --fail-under=99. #1470
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Nov 6, 2022
1 parent 79a53f2 commit 4371697
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -25,12 +25,16 @@ Unreleased
use ``--format=markdown`` to get the table in Markdown format, thanks to
Steve Oswald in `pull 1479`_, closing `issue 1418`_.

- An empty file has a coverage total of 100%, but used to fail with
``--fail-under``. This has been fixed, closing `issue 1470`_.

- Fixed a mis-measurement of a strange use of wildcard alternatives in
match/case statements, closing `issue 1421`_.

.. _pull 1479: https://github.com/nedbat/coveragepy/pull/1479
.. _issue 1418: https://github.com/nedbat/coveragepy/issues/1418
.. _issue 1421: https://github.com/nedbat/coveragepy/issues/1421
.. _issue 1470: https://github.com/nedbat/coveragepy/issues/1470


.. _changes_6-6-0b1:
Expand Down
2 changes: 1 addition & 1 deletion coverage/summary.py
Expand Up @@ -165,7 +165,7 @@ def report(self, morfs, outfile=None):
else:
self.tabular_report()

return self.total.n_statements and self.total.pc_covered
return self.total.pc_covered

def tabular_report(self):
"""Writes tabular report formats."""
Expand Down
3 changes: 2 additions & 1 deletion tests/test_process.py
Expand Up @@ -1093,7 +1093,8 @@ def test_report(self):
st, _ = self.run_command_status("coverage run empty.py")
assert st == 0
st, _ = self.run_command_status("coverage report")
assert st == 2
# An empty file is marked as 100% covered, so this is ok.
assert st == 0


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

0 comments on commit 4371697

Please sign in to comment.