Skip to content

Commit b523627

Browse files
committed
Add run-report to command line
* run-report can be used to show a report without creating a .coverage file
1 parent 62434e7 commit b523627

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

coverage/cmdline.py

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,34 @@ def get_prog_name(self) -> str:
538538
description="Run a Python program, measuring code execution.",
539539
),
540540

541+
"run-report": CmdOptionParser(
542+
"run-report",
543+
[
544+
Opts.append,
545+
Opts.branch,
546+
Opts.concurrency,
547+
Opts.context,
548+
Opts.fail_under,
549+
Opts.format,
550+
Opts.ignore_errors,
551+
Opts.include,
552+
Opts.module,
553+
Opts.no_skip_covered,
554+
Opts.omit,
555+
Opts.precision,
556+
Opts.parallel_mode,
557+
Opts.pylib,
558+
Opts.save_signal,
559+
Opts.skip_covered,
560+
Opts.skip_empty,
561+
Opts.sort,
562+
Opts.source,
563+
Opts.timid,
564+
] + GLOBAL_ARGS,
565+
usage="[options] <pyfile> [program options]",
566+
description="Run a Python program, measuring code execution and report without saving in file.",
567+
),
568+
541569
"xml": CmdOptionParser(
542570
"xml",
543571
[
@@ -662,7 +690,7 @@ def command_line(self, argv: list[str]) -> int:
662690

663691
# Do something.
664692
self.coverage = Coverage(
665-
data_file=options.data_file or DEFAULT_DATAFILE,
693+
data_file=None if options.action == "run-report" else options.data_file or DEFAULT_DATAFILE,
666694
data_suffix=options.parallel_mode,
667695
cover_pylib=options.pylib,
668696
timid=options.timid,
@@ -688,6 +716,9 @@ def command_line(self, argv: list[str]) -> int:
688716
elif options.action == "run":
689717
return self.do_run(options, args)
690718

719+
elif options.action == "run-report":
720+
return self.do_run(options, args, report=True)
721+
691722
elif options.action == "combine":
692723
if options.append:
693724
self.coverage.load()
@@ -820,7 +851,7 @@ def do_signal_save(self, _signum: int, _frame: types.FrameType | None) -> None:
820851
print("Saving coverage data...", flush=True)
821852
self.coverage.save()
822853

823-
def do_run(self, options: optparse.Values, args: list[str]) -> int:
854+
def do_run(self, options: optparse.Values, args: list[str], report=False) -> int:
824855
"""Implementation of 'coverage run'."""
825856

826857
if not args:
@@ -882,7 +913,17 @@ def do_run(self, options: optparse.Values, args: list[str]) -> int:
882913
finally:
883914
self.coverage.stop()
884915
if code_ran:
885-
self.coverage.save()
916+
if report:
917+
self.coverage.report(
918+
precision=options.precision,
919+
show_missing=True,
920+
skip_covered=options.skip_covered,
921+
skip_empty=options.skip_empty,
922+
sort=options.sort,
923+
output_format=options.format
924+
)
925+
else:
926+
self.coverage.save()
886927

887928
return OK
888929

0 commit comments

Comments
 (0)