Skip to content

Commit

Permalink
feat: mention skipped file counts in the HTML report. #1163
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Aug 6, 2021
1 parent a17f6ee commit a99b27f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -30,6 +30,9 @@ Unreleased
- The ``coverage combine`` command now prints messages indicating each data
file being combined. Fixes `issue 1105`_.

- The HTML report now includes a sentence about skipped files due to
``skip_covered`` or ``skip_empty`` settings. Fixes `issue 1163`_.

- Unrecognized options in the configuration file are no longer errors. They are
now warnings, to ease the use of coverage across versions. Fixes `issue
1035`_.
Expand All @@ -39,6 +42,7 @@ Unreleased

.. _issue 1035: https://github.com/nedbat/coveragepy/issues/1035
.. _issue 1105: https://github.com/nedbat/coveragepy/issues/1105
.. _issue 1163: https://github.com/nedbat/coveragepy/issues/1163
.. _issue 1195: https://github.com/nedbat/coveragepy/issues/1195


Expand Down
22 changes: 21 additions & 1 deletion coverage/html.py
Expand Up @@ -179,7 +179,9 @@ def __init__(self, cov):
self.skip_covered = self.config.skip_covered
self.skip_empty = self.config.html_skip_empty
if self.skip_empty is None:
self.skip_empty= self.config.skip_empty
self.skip_empty = self.config.skip_empty
self.skipped_covered_count = 0
self.skipped_empty_count = 0

title = self.config.html_title

Expand Down Expand Up @@ -284,12 +286,14 @@ def html_file(self, fr, analysis):
if no_missing_lines and no_missing_branches:
# If there's an existing file, remove it.
file_be_gone(html_path)
self.skipped_covered_count += 1
return

if self.skip_empty:
# Don't report on empty files.
if nums.n_statements == 0:
file_be_gone(html_path)
self.skipped_empty_count += 1
return

# Find out if the file on disk is already correct.
Expand Down Expand Up @@ -358,9 +362,25 @@ def index_file(self):
"""Write the index.html file for this report."""
index_tmpl = Templite(read_data("index.html"), self.template_globals)

skipped_covered_msg = skipped_empty_msg = ""
if self.skipped_covered_count:
msg = "{} {} skipped due to complete coverage."
skipped_covered_msg = msg.format(
self.skipped_covered_count,
"file" if self.skipped_covered_count == 1 else "files",
)
if self.skipped_empty_count:
msg = "{} empty {} skipped."
skipped_empty_msg = msg.format(
self.skipped_empty_count,
"file" if self.skipped_empty_count == 1 else "files",
)

html = index_tmpl.render({
'files': self.file_summaries,
'totals': self.totals,
'skipped_covered_msg': skipped_covered_msg,
'skipped_empty_msg': skipped_empty_msg,
})

index_file = os.path.join(self.directory, "index.html")
Expand Down
7 changes: 7 additions & 0 deletions coverage/htmlfiles/index.html
Expand Up @@ -104,6 +104,13 @@ <h1>{{ title|escape }}:
<p id="no_rows">
No items found using the specified filter.
</p>

{% if skipped_covered_msg %}
<p>{{ skipped_covered_msg }}</p>
{% endif %}
{% if skipped_empty_msg %}
<p>{{ skipped_empty_msg }}</p>
{% endif %}
</div>

<div id="footer">
Expand Down
4 changes: 4 additions & 0 deletions tests/test_html.py
Expand Up @@ -506,6 +506,8 @@ def test_html_skip_covered(self):
self.assert_exists("htmlcov/index.html")
self.assert_doesnt_exist("htmlcov/main_file_py.html")
self.assert_exists("htmlcov/not_covered_py.html")
index = self.get_html_index_content()
assert "1 file skipped due to complete coverage." in index

def test_report_skip_covered_branches(self):
self.make_main_and_not_covered()
Expand Down Expand Up @@ -541,6 +543,8 @@ def test_report_skip_empty(self):
self.assert_exists("htmlcov/index.html")
self.assert_exists("htmlcov/main_file_py.html")
self.assert_doesnt_exist("htmlcov/submodule___init___py.html")
index = self.get_html_index_content()
assert "1 empty file skipped." in index

def test_html_skip_empty(self):
self.make_init_and_main()
Expand Down

0 comments on commit a99b27f

Please sign in to comment.