diff options
-rw-r--r-- | coverage/summary.py | 3 | ||||
-rw-r--r-- | tests/test_cmdline.py | 5 | ||||
-rw-r--r-- | tests/test_summary.py | 6 |
3 files changed, 13 insertions, 1 deletions
diff --git a/coverage/summary.py b/coverage/summary.py index fe73c678..24aa30f2 100644 --- a/coverage/summary.py +++ b/coverage/summary.py @@ -20,11 +20,12 @@ class SummaryReporter: self.branches = coverage.get_data().has_arcs() self.outfile = None self.output_format = self.config.format or "text" + if self.output_format not in {"text", "markdown", "total"}: + raise ConfigError(f"Unknown report format choice: {self.output_format!r}") self.fr_analysis = [] self.skipped_count = 0 self.empty_count = 0 self.total = Numbers(precision=self.config.precision) - self.fmt_err = "%s %s: %s" def write(self, line): """Write a line to the output, adding a newline.""" diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 378c901d..96e7ffb9 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -585,6 +585,11 @@ class CmdLineTest(BaseCmdLineTest): cov.load() cov.report(show_missing=None) """) + self.cmd_executes("report --format=markdown", """\ + cov = Coverage() + cov.load() + cov.report(output_format="markdown") + """) def test_run(self): # coverage run [-p] [-L] [--timid] MODULE.py [ARG1 ARG2 ...] diff --git a/tests/test_summary.py b/tests/test_summary.py index 82508de8..f0f16aa2 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -1001,3 +1001,9 @@ class SummaryReporterConfigurationTest(CoverageTest): msg = "Invalid sorting option: 'Xyzzy'" with pytest.raises(ConfigError, match=msg): self.get_summary_text(('report:sort', 'Xyzzy')) + + def test_report_with_invalid_format(self): + # Ask for an invalid format. + msg = "Unknown report format choice: 'xyzzy'" + with pytest.raises(ConfigError, match=msg): + self.get_summary_text(('report:format', 'xyzzy')) |