diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2022-11-06 12:31:35 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-11-06 13:33:53 -0500 |
commit | d5c3daa5b6f15f968e663f1a0459ddad48479e67 (patch) | |
tree | 39453ae6cb48d950790000f836f2a023adea28cd | |
parent | e5a15c1d5652574ba85673f814b09f5da333fca8 (diff) | |
download | python-coveragepy-git-d5c3daa5b6f15f968e663f1a0459ddad48479e67.tar.gz |
fix: an empty file shouldn't fail with --fail-under=99. #1470
-rw-r--r-- | CHANGES.rst | 4 | ||||
-rw-r--r-- | coverage/summary.py | 2 | ||||
-rw-r--r-- | tests/test_process.py | 3 |
3 files changed, 7 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index a03c052c..960cb9c6 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 d1919e71..194dc1af 100644 --- a/coverage/summary.py +++ b/coverage/summary.py @@ -165,7 +165,7 @@ class SummaryReporter: 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 b76846e5..1f134a6d 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -1093,7 +1093,8 @@ class FailUnderEmptyFilesTest(CoverageTest): 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.") |