diff options
author | Nikita Bloshchanevich <nikblos@outlook.com> | 2022-01-15 14:47:01 +0100 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-01-25 08:23:10 -0500 |
commit | ba884e41506fd6e8f6eca91a13fe1661b3220c5e (patch) | |
tree | 7e89a6e6bbf7c3b08cc5943cb2c10cf9865a7712 /coverage | |
parent | cfe14c266dcd405422bb775c9d45779f7a21715f (diff) | |
download | python-coveragepy-git-ba884e41506fd6e8f6eca91a13fe1661b3220c5e.tar.gz |
feat: use --data-file to configure the coverage database
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/cmdline.py | 31 | ||||
-rw-r--r-- | coverage/control.py | 7 |
2 files changed, 29 insertions, 9 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index ad19ef29..f7da33df 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -18,6 +18,7 @@ from coverage import Coverage from coverage import env from coverage.collector import CTracer from coverage.config import CoverageConfig +from coverage.control import DEFAULT_DATAFILE from coverage.data import combinable_files, debug_data_file from coverage.debug import info_formatter, info_header, short_stack from coverage.exceptions import _BaseCoverageException, _ExceptionDuringRun, NoSource @@ -128,6 +129,17 @@ class Opts: metavar="OUTFILE", help="Write the LCOV report to this file. Defaults to 'coverage.lcov'", ) + output_coverage = optparse.make_option( + '', '--data-file', action='store', dest="output_coverage", + metavar="OUTFILE", + help="Write the recorded coverage information to this file. Defaults to '.coverage'" + ) + input_coverage = optparse.make_option( + '', '--data-file', action='store', dest="input_coverage", + metavar="INPUT", + help="Read coverage data for report generation from this file (needed if you have " + "specified -o previously). Defaults to '.coverage'" + ) json_pretty_print = optparse.make_option( '', '--pretty-print', action='store_true', help="Format the JSON for human readers.", @@ -325,6 +337,8 @@ GLOBAL_ARGS = [ Opts.rcfile, ] +REPORT_ARGS = [Opts.input_coverage] + CMDS = { 'annotate': CmdOptionParser( "annotate", @@ -333,7 +347,7 @@ CMDS = { Opts.ignore_errors, Opts.include, Opts.omit, - ] + GLOBAL_ARGS, + ] + REPORT_ARGS + GLOBAL_ARGS, usage="[options] [modules]", description=( "Make annotated copies of the given files, marking statements that are executed " + @@ -347,6 +361,7 @@ CMDS = { Opts.append, Opts.keep, Opts.quiet, + Opts.output_coverage ] + GLOBAL_ARGS, usage="[options] <path1> <path2> ... <pathN>", description=( @@ -374,7 +389,7 @@ CMDS = { ), 'erase': CmdOptionParser( - "erase", GLOBAL_ARGS, + "erase", [Opts.input_coverage] + GLOBAL_ARGS, description="Erase previously collected coverage data.", ), @@ -400,7 +415,7 @@ CMDS = { Opts.no_skip_covered, Opts.skip_empty, Opts.title, - ] + GLOBAL_ARGS, + ] + REPORT_ARGS + GLOBAL_ARGS, usage="[options] [modules]", description=( "Create an HTML report of the coverage of the files. " + @@ -421,7 +436,7 @@ CMDS = { Opts.json_pretty_print, Opts.quiet, Opts.show_contexts, - ] + GLOBAL_ARGS, + ] + REPORT_ARGS + GLOBAL_ARGS, usage="[options] [modules]", description="Generate a JSON report of coverage results.", ), @@ -454,7 +469,7 @@ CMDS = { Opts.skip_covered, Opts.no_skip_covered, Opts.skip_empty, - ] + GLOBAL_ARGS, + ] + REPORT_ARGS + GLOBAL_ARGS, usage="[options] [modules]", description="Report coverage statistics on modules.", ), @@ -469,6 +484,7 @@ CMDS = { Opts.include, Opts.module, Opts.omit, + Opts.output_coverage, Opts.pylib, Opts.parallel_mode, Opts.source, @@ -488,7 +504,7 @@ CMDS = { Opts.output_xml, Opts.quiet, Opts.skip_empty, - ] + GLOBAL_ARGS, + ] + REPORT_ARGS + GLOBAL_ARGS, usage="[options] [modules]", description="Generate an XML report of coverage results.", ), @@ -591,8 +607,11 @@ class CoverageScript: else: concurrency = None + data_file = getattr(options, "output_coverage", None) \ + or getattr(options, "input_coverage", None) # Do something. self.coverage = Coverage( + data_file=data_file or DEFAULT_DATAFILE, data_suffix=options.parallel_mode, cover_pylib=options.pylib, timid=options.timid, diff --git a/coverage/control.py b/coverage/control.py index 913d6893..0f62198a 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -62,7 +62,8 @@ def override_config(cov, **kwargs): cov.config = original_config -_DEFAULT_DATAFILE = DefaultValue("MISSING") +DEFAULT_DATAFILE = DefaultValue("MISSING") +_DEFAULT_DATAFILE = DEFAULT_DATAFILE # Just in case, for backwards compatibility class Coverage: """Programmatic access to coverage.py. @@ -103,7 +104,7 @@ class Coverage: return None def __init__( - self, data_file=_DEFAULT_DATAFILE, data_suffix=None, cover_pylib=None, + self, data_file=DEFAULT_DATAFILE, data_suffix=None, cover_pylib=None, auto_data=False, timid=None, branch=None, config_file=True, source=None, source_pkgs=None, omit=None, include=None, debug=None, concurrency=None, check_preimported=False, context=None, @@ -200,7 +201,7 @@ class Coverage: # data_file=None means no disk file at all. data_file missing means # use the value from the config file. self._no_disk = data_file is None - if data_file is _DEFAULT_DATAFILE: + if data_file is DEFAULT_DATAFILE: data_file = None self.config = None |