1818from coverage import env
1919from coverage .collector import CTracer
2020from coverage .config import CoverageConfig
21+ from coverage .control import DEFAULT_DATAFILE
2122from coverage .data import combinable_files , debug_data_file
2223from coverage .debug import info_formatter , info_header , short_stack
2324from coverage .exceptions import _BaseCoverageException , _ExceptionDuringRun , NoSource
@@ -128,6 +129,17 @@ class Opts:
128129 metavar = "OUTFILE" ,
129130 help = "Write the LCOV report to this file. Defaults to 'coverage.lcov'" ,
130131 )
132+ output_coverage = optparse .make_option (
133+ '' , '--data-file' , action = 'store' , dest = "output_coverage" ,
134+ metavar = "OUTFILE" ,
135+ help = "Write the recorded coverage information to this file. Defaults to '.coverage'"
136+ )
137+ input_coverage = optparse .make_option (
138+ '' , '--data-file' , action = 'store' , dest = "input_coverage" ,
139+ metavar = "INPUT" ,
140+ help = "Read coverage data for report generation from this file (needed if you have "
141+ "specified -o previously). Defaults to '.coverage'"
142+ )
131143 json_pretty_print = optparse .make_option (
132144 '' , '--pretty-print' , action = 'store_true' ,
133145 help = "Format the JSON for human readers." ,
@@ -325,6 +337,8 @@ def get_prog_name(self):
325337 Opts .rcfile ,
326338 ]
327339
340+ REPORT_ARGS = [Opts .input_coverage ]
341+
328342CMDS = {
329343 'annotate' : CmdOptionParser (
330344 "annotate" ,
@@ -333,7 +347,7 @@ def get_prog_name(self):
333347 Opts .ignore_errors ,
334348 Opts .include ,
335349 Opts .omit ,
336- ] + GLOBAL_ARGS ,
350+ ] + REPORT_ARGS + GLOBAL_ARGS ,
337351 usage = "[options] [modules]" ,
338352 description = (
339353 "Make annotated copies of the given files, marking statements that are executed " +
@@ -347,6 +361,7 @@ def get_prog_name(self):
347361 Opts .append ,
348362 Opts .keep ,
349363 Opts .quiet ,
364+ Opts .output_coverage
350365 ] + GLOBAL_ARGS ,
351366 usage = "[options] <path1> <path2> ... <pathN>" ,
352367 description = (
@@ -374,7 +389,7 @@ def get_prog_name(self):
374389 ),
375390
376391 'erase' : CmdOptionParser (
377- "erase" , GLOBAL_ARGS ,
392+ "erase" , [ Opts . input_coverage ] + GLOBAL_ARGS ,
378393 description = "Erase previously collected coverage data." ,
379394 ),
380395
@@ -400,7 +415,7 @@ def get_prog_name(self):
400415 Opts .no_skip_covered ,
401416 Opts .skip_empty ,
402417 Opts .title ,
403- ] + GLOBAL_ARGS ,
418+ ] + REPORT_ARGS + GLOBAL_ARGS ,
404419 usage = "[options] [modules]" ,
405420 description = (
406421 "Create an HTML report of the coverage of the files. " +
@@ -421,7 +436,7 @@ def get_prog_name(self):
421436 Opts .json_pretty_print ,
422437 Opts .quiet ,
423438 Opts .show_contexts ,
424- ] + GLOBAL_ARGS ,
439+ ] + REPORT_ARGS + GLOBAL_ARGS ,
425440 usage = "[options] [modules]" ,
426441 description = "Generate a JSON report of coverage results." ,
427442 ),
@@ -454,7 +469,7 @@ def get_prog_name(self):
454469 Opts .skip_covered ,
455470 Opts .no_skip_covered ,
456471 Opts .skip_empty ,
457- ] + GLOBAL_ARGS ,
472+ ] + REPORT_ARGS + GLOBAL_ARGS ,
458473 usage = "[options] [modules]" ,
459474 description = "Report coverage statistics on modules." ,
460475 ),
@@ -469,6 +484,7 @@ def get_prog_name(self):
469484 Opts .include ,
470485 Opts .module ,
471486 Opts .omit ,
487+ Opts .output_coverage ,
472488 Opts .pylib ,
473489 Opts .parallel_mode ,
474490 Opts .source ,
@@ -488,7 +504,7 @@ def get_prog_name(self):
488504 Opts .output_xml ,
489505 Opts .quiet ,
490506 Opts .skip_empty ,
491- ] + GLOBAL_ARGS ,
507+ ] + REPORT_ARGS + GLOBAL_ARGS ,
492508 usage = "[options] [modules]" ,
493509 description = "Generate an XML report of coverage results." ,
494510 ),
@@ -591,8 +607,11 @@ def command_line(self, argv):
591607 else :
592608 concurrency = None
593609
610+ data_file = getattr (options , "output_coverage" , None ) \
611+ or getattr (options , "input_coverage" , None )
594612 # Do something.
595613 self .coverage = Coverage (
614+ data_file = data_file or DEFAULT_DATAFILE ,
596615 data_suffix = options .parallel_mode ,
597616 cover_pylib = options .pylib ,
598617 timid = options .timid ,
0 commit comments