From f280232d1be1d67ecfc20696c3d0fc3c52794567 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 6 Nov 2022 12:31:35 -0500 Subject: [PATCH] fix: an empty file shouldn't fail with --fail-under=99. #1470 --- CHANGES.rst | 4 ++++ coverage/summary.py | 2 +- tests/test_process.py | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index a03c052c9..960cb9c61 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -29,12 +29,16 @@ Unreleased - Using ``--format=total`` will write a single total number to the output. This can be useful for making badges or writing status updates. +- 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: diff --git a/coverage/summary.py b/coverage/summary.py index d1919e714..194dc1afa 100644 --- a/coverage/summary.py +++ b/coverage/summary.py @@ -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.""" diff --git a/tests/test_process.py b/tests/test_process.py index b76846e51..1f134a6da 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -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.")