diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2022-11-06 12:17:11 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-11-06 13:33:53 -0500 |
commit | e5a15c1d5652574ba85673f814b09f5da333fca8 (patch) | |
tree | 889dc8497bfb1817f91d8322f74ba35db5efceb2 /coverage | |
parent | 30f1ecf0657fa89b56eab300f10c58852edbbcdd (diff) | |
download | python-coveragepy-git-e5a15c1d5652574ba85673f814b09f5da333fca8.tar.gz |
feat: --format=total writes just the total number
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/cmdline.py | 2 | ||||
-rw-r--r-- | coverage/control.py | 2 | ||||
-rw-r--r-- | coverage/summary.py | 15 |
3 files changed, 13 insertions, 6 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index bea95993..b15a66f7 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -98,7 +98,7 @@ class Opts: ) format = optparse.make_option( '', '--format', action='store', metavar="FORMAT", - help="Output format, either text (default) or markdown", + help="Output format, either text (default), markdown, or total.", ) help = optparse.make_option( '-h', '--help', action='store_true', diff --git a/coverage/control.py b/coverage/control.py index d260eeab..9a55acb1 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -924,7 +924,7 @@ class Coverage: `file` is a file-like object, suitable for writing. `output_format` determines the format, either "text" (the default), - or "markdown". + "markdown", or "total". `include` is a list of file name patterns. Files that match will be included in the report. Files matching `omit` will not be included in diff --git a/coverage/summary.py b/coverage/summary.py index 1aa802af..d1919e71 100644 --- a/coverage/summary.py +++ b/coverage/summary.py @@ -19,6 +19,7 @@ class SummaryReporter: self.config = self.coverage.config self.branches = coverage.get_data().has_arcs() self.outfile = None + self.output_format = self.config.format or "text" self.fr_analysis = [] self.skipped_count = 0 self.empty_count = 0 @@ -159,6 +160,15 @@ class SummaryReporter: if not self.total.n_files and not self.skipped_count: raise NoDataError("No data to report.") + if self.output_format == "total": + self.write(self.total.pc_covered_str) + else: + self.tabular_report() + + return self.total.n_statements and self.total.pc_covered + + def tabular_report(self): + """Writes tabular report formats.""" # Prepare the header line and column sorting. header = ["Name", "Stmts", "Miss"] if self.branches: @@ -221,15 +231,12 @@ class SummaryReporter: file_suffix = 's' if self.empty_count > 1 else '' end_lines.append(f"\n{self.empty_count} empty file{file_suffix} skipped.") - text_format = self.config.format or "text" - if text_format == "markdown": + if self.output_format == "markdown": formatter = self._report_markdown else: formatter = self._report_text formatter(header, lines_values, total_line, end_lines) - return self.total.n_statements and self.total.pc_covered - def report_one_file(self, fr, analysis): """Report on just one file, the callback from report().""" nums = analysis.numbers |