18
18
from coverage import env
19
19
from coverage .collector import CTracer
20
20
from coverage .config import CoverageConfig
21
+ from coverage .control import DEFAULT_DATAFILE
21
22
from coverage .data import combinable_files , debug_data_file
22
23
from coverage .debug import info_formatter , info_header , short_stack
23
24
from coverage .exceptions import _BaseCoverageException , _ExceptionDuringRun , NoSource
@@ -128,6 +129,17 @@ class Opts:
128
129
metavar = "OUTFILE" ,
129
130
help = "Write the LCOV report to this file. Defaults to 'coverage.lcov'" ,
130
131
)
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
+ )
131
143
json_pretty_print = optparse .make_option (
132
144
'' , '--pretty-print' , action = 'store_true' ,
133
145
help = "Format the JSON for human readers." ,
@@ -325,6 +337,8 @@ def get_prog_name(self):
325
337
Opts .rcfile ,
326
338
]
327
339
340
+ REPORT_ARGS = [Opts .input_coverage ]
341
+
328
342
CMDS = {
329
343
'annotate' : CmdOptionParser (
330
344
"annotate" ,
@@ -333,7 +347,7 @@ def get_prog_name(self):
333
347
Opts .ignore_errors ,
334
348
Opts .include ,
335
349
Opts .omit ,
336
- ] + GLOBAL_ARGS ,
350
+ ] + REPORT_ARGS + GLOBAL_ARGS ,
337
351
usage = "[options] [modules]" ,
338
352
description = (
339
353
"Make annotated copies of the given files, marking statements that are executed " +
@@ -347,6 +361,7 @@ def get_prog_name(self):
347
361
Opts .append ,
348
362
Opts .keep ,
349
363
Opts .quiet ,
364
+ Opts .output_coverage
350
365
] + GLOBAL_ARGS ,
351
366
usage = "[options] <path1> <path2> ... <pathN>" ,
352
367
description = (
@@ -374,7 +389,7 @@ def get_prog_name(self):
374
389
),
375
390
376
391
'erase' : CmdOptionParser (
377
- "erase" , GLOBAL_ARGS ,
392
+ "erase" , [ Opts . input_coverage ] + GLOBAL_ARGS ,
378
393
description = "Erase previously collected coverage data." ,
379
394
),
380
395
@@ -400,7 +415,7 @@ def get_prog_name(self):
400
415
Opts .no_skip_covered ,
401
416
Opts .skip_empty ,
402
417
Opts .title ,
403
- ] + GLOBAL_ARGS ,
418
+ ] + REPORT_ARGS + GLOBAL_ARGS ,
404
419
usage = "[options] [modules]" ,
405
420
description = (
406
421
"Create an HTML report of the coverage of the files. " +
@@ -421,7 +436,7 @@ def get_prog_name(self):
421
436
Opts .json_pretty_print ,
422
437
Opts .quiet ,
423
438
Opts .show_contexts ,
424
- ] + GLOBAL_ARGS ,
439
+ ] + REPORT_ARGS + GLOBAL_ARGS ,
425
440
usage = "[options] [modules]" ,
426
441
description = "Generate a JSON report of coverage results." ,
427
442
),
@@ -454,7 +469,7 @@ def get_prog_name(self):
454
469
Opts .skip_covered ,
455
470
Opts .no_skip_covered ,
456
471
Opts .skip_empty ,
457
- ] + GLOBAL_ARGS ,
472
+ ] + REPORT_ARGS + GLOBAL_ARGS ,
458
473
usage = "[options] [modules]" ,
459
474
description = "Report coverage statistics on modules." ,
460
475
),
@@ -469,6 +484,7 @@ def get_prog_name(self):
469
484
Opts .include ,
470
485
Opts .module ,
471
486
Opts .omit ,
487
+ Opts .output_coverage ,
472
488
Opts .pylib ,
473
489
Opts .parallel_mode ,
474
490
Opts .source ,
@@ -488,7 +504,7 @@ def get_prog_name(self):
488
504
Opts .output_xml ,
489
505
Opts .quiet ,
490
506
Opts .skip_empty ,
491
- ] + GLOBAL_ARGS ,
507
+ ] + REPORT_ARGS + GLOBAL_ARGS ,
492
508
usage = "[options] [modules]" ,
493
509
description = "Generate an XML report of coverage results." ,
494
510
),
@@ -591,8 +607,11 @@ def command_line(self, argv):
591
607
else :
592
608
concurrency = None
593
609
610
+ data_file = getattr (options , "output_coverage" , None ) \
611
+ or getattr (options , "input_coverage" , None )
594
612
# Do something.
595
613
self .coverage = Coverage (
614
+ data_file = data_file or DEFAULT_DATAFILE ,
596
615
data_suffix = options .parallel_mode ,
597
616
cover_pylib = options .pylib ,
598
617
timid = options .timid ,
0 commit comments