From a99b27f730a262585514cc358213aa5d4c350c11 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 6 Aug 2021 07:05:50 -0400 Subject: feat: mention skipped file counts in the HTML report. #1163 --- CHANGES.rst | 4 ++++ coverage/html.py | 22 +++++++++++++++++++++- coverage/htmlfiles/index.html | 7 +++++++ tests/test_html.py | 4 ++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 600c71f8..0fc84cb3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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`_. @@ -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 diff --git a/coverage/html.py b/coverage/html.py index 95e3aa44..208554c8 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -179,7 +179,9 @@ class HtmlReporter: 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 @@ -284,12 +286,14 @@ class HtmlReporter: 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. @@ -358,9 +362,25 @@ class HtmlReporter: """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") diff --git a/coverage/htmlfiles/index.html b/coverage/htmlfiles/index.html index 983db061..3654d66a 100644 --- a/coverage/htmlfiles/index.html +++ b/coverage/htmlfiles/index.html @@ -104,6 +104,13 @@

No items found using the specified filter.

+ + {% if skipped_covered_msg %} +

{{ skipped_covered_msg }}

+ {% endif %} + {% if skipped_empty_msg %} +

{{ skipped_empty_msg }}

+ {% endif %}