diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2022-11-06 12:44:36 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-11-06 13:33:53 -0500 |
commit | 8389674d5d0f15dcb84896439f74ada0bc2150da (patch) | |
tree | bf64bd9161a4667f0af744e5b1263b3a9a79ffbb | |
parent | d5c3daa5b6f15f968e663f1a0459ddad48479e67 (diff) | |
download | python-coveragepy-git-8389674d5d0f15dcb84896439f74ada0bc2150da.tar.gz |
fix: don't write two rules for an empty table.
-rw-r--r-- | CHANGES.rst | 3 | ||||
-rw-r--r-- | coverage/summary.py | 4 | ||||
-rw-r--r-- | tests/test_summary.py | 21 |
3 files changed, 16 insertions, 12 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 960cb9c6..1f622b72 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -32,6 +32,9 @@ Unreleased - An empty file has a coverage total of 100%, but used to fail with ``--fail-under``. This has been fixed, closing `issue 1470`_. +- The text report table no longer writes out two separator lines if there are + no files listed in the table. One is plenty. + - Fixed a mis-measurement of a strange use of wildcard alternatives in match/case statements, closing `issue 1421`_. diff --git a/coverage/summary.py b/coverage/summary.py index 194dc1af..fe73c678 100644 --- a/coverage/summary.py +++ b/coverage/summary.py @@ -78,7 +78,9 @@ class SummaryReporter: self.write_items(line_items) # Write a TOTAL line - self.write(rule) + if lines_values: + self.write(rule) + line_items = [ formats[item].format(str(value), name_len=max_name, n=max_n-1) for item, value in zip(header, total_line) diff --git a/tests/test_summary.py b/tests/test_summary.py index e32a1d2e..82508de8 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -409,17 +409,18 @@ class SummaryTest(UsingModulesMixin, CoverageTest): assert self.stdout() == "" report = self.get_report(cov, skip_covered=True) - # Name Stmts Miss Branch BrPart Cover - # ------------------------------------------- + # Name Stmts Miss Branch BrPart Cover # ----------------------------------------- # TOTAL 3 0 0 0 100% # # 1 file skipped due to complete coverage. - assert self.line_count(report) == 6, report + assert self.line_count(report) == 5, report squeezed = self.squeezed_lines(report) - assert squeezed[5] == "1 file skipped due to complete coverage." + assert squeezed[4] == "1 file skipped due to complete coverage." + report = self.get_report(cov, squeeze=False, skip_covered=True, output_format="markdown") + # | Name | Stmts | Miss | Branch | BrPart | Cover | # |---------- | -------: | -------: | -------: | -------: | -------: | # | **TOTAL** | **3** | **0** | **0** | **0** | **100%** | @@ -455,16 +456,15 @@ class SummaryTest(UsingModulesMixin, CoverageTest): # Name Stmts Miss Branch BrPart Cover # ----------------------------------------- - # ----------------------------------------- # TOTAL 3 0 0 0 100% # # 1 file skipped due to complete coverage. - assert self.line_count(report) == 6, report + assert self.line_count(report) == 5, report lines = self.report_lines(report) assert lines[0] == "Name Stmts Miss Branch BrPart Cover" squeezed = self.squeezed_lines(report) - assert squeezed[5] == "1 file skipped due to complete coverage." + assert squeezed[4] == "1 file skipped due to complete coverage." def test_report_skip_covered_no_data(self): cov = coverage.Coverage() @@ -510,14 +510,13 @@ class SummaryTest(UsingModulesMixin, CoverageTest): # Name Stmts Miss Cover # ------------------------------------ - # ------------------------------------ # TOTAL 0 0 100% # # 1 empty file skipped. - assert self.line_count(report) == 6, report - assert report.split("\n")[3] == "TOTAL 0 0 100%" - assert report.split("\n")[5] == "1 empty file skipped." + assert self.line_count(report) == 5, report + assert report.split("\n")[2] == "TOTAL 0 0 100%" + assert report.split("\n")[4] == "1 empty file skipped." def test_report_precision(self): self.make_file(".coveragerc", """\ |