diff options
-rw-r--r-- | CHANGES.rst | 6 | ||||
-rw-r--r-- | CONTRIBUTORS.txt | 1 | ||||
-rw-r--r-- | coverage/cmdline.py | 47 | ||||
-rw-r--r-- | doc/cmd.rst | 67 |
4 files changed, 78 insertions, 43 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index dbeaca2c..1113b71d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -25,6 +25,11 @@ Unreleased - Feature: Added the `lcov` command to generate reports in LCOV format. Thanks, Bradley Burns. Closes `issue 587`_ and `issue 626`_. +- Feature: the coverage data file can now be specified on the command line with + the ``--data-file`` option in any command that reads or writes data. This is + in addition to the existing ``COVERAGE_FILE`` environment variable. Closes + `issue 624`_. Thanks, Nikita Bloshchanevich. + - Feature: coverage measurement data will now be written when a SIGTERM signal is received by the process. This includes :meth:`Process.terminate <python:multiprocessing.Process.terminate>`, @@ -46,6 +51,7 @@ Unreleased - Releases now have MacOS arm64 wheels for Apple Silicon (fixes `issue 1288`_). .. _issue 587: https://github.com/nedbat/coveragepy/issues/587 +.. _issue 624: https://github.com/nedbat/coveragepy/issues/624 .. _issue 626: https://github.com/nedbat/coveragepy/issues/626 .. _issue 883: https://github.com/nedbat/coveragepy/issues/883 .. _issue 1288: https://github.com/nedbat/coveragepy/issues/1288 diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index e422cd2a..9f3d0b20 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -109,6 +109,7 @@ Mickie Betz Mike Fiedler Naveen Yadav Nathan Land +Nikita Bloshchanevich Nils Kattenbeck Noel O'Boyle Olivier Grisel diff --git a/coverage/cmdline.py b/coverage/cmdline.py index f7da33df..fccfe75a 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -60,6 +60,27 @@ class Opts: "Accepts Python regexes, which must be quoted." ), ) + combine_datafile = optparse.make_option( + '', '--data-file', action='store', metavar="DATAFILE", + help=( + "Base name of the data files to combine and write. " + + "Defaults to '.coverage'. [env: COVERAGE_FILE]" + ), + ) + input_datafile = optparse.make_option( + '', '--data-file', action='store', metavar="INFILE", + help=( + "Read coverage data for report generation from this file. " + + "Defaults to '.coverage'. [env: COVERAGE_FILE]" + ), + ) + output_datafile = optparse.make_option( + '', '--data-file', action='store', metavar="OUTFILE", + help=( + "Write the recorded coverage data to this file. " + + "Defaults to '.coverage'. [env: COVERAGE_FILE]" + ), + ) debug = optparse.make_option( '', '--debug', action='store', metavar="OPTS", help="Debug options, separated by commas. [env: COVERAGE_DEBUG]", @@ -129,17 +150,6 @@ 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.", @@ -148,7 +158,7 @@ class Opts: '-p', '--parallel-mode', action='store_true', help=( "Append the machine name, process id and random number to the " + - ".coverage data file name to simplify collecting data from " + + "data file name to simplify collecting data from " + "many processes." ), ) @@ -232,6 +242,7 @@ class CoverageOptionParser(optparse.OptionParser): concurrency=None, context=None, contexts=None, + data_file=None, debug=None, directory=None, fail_under=None, @@ -337,7 +348,7 @@ GLOBAL_ARGS = [ Opts.rcfile, ] -REPORT_ARGS = [Opts.input_coverage] +REPORT_ARGS = [Opts.input_datafile] CMDS = { 'annotate': CmdOptionParser( @@ -361,7 +372,7 @@ CMDS = { Opts.append, Opts.keep, Opts.quiet, - Opts.output_coverage + Opts.combine_datafile ] + GLOBAL_ARGS, usage="[options] <path1> <path2> ... <pathN>", description=( @@ -389,7 +400,7 @@ CMDS = { ), 'erase': CmdOptionParser( - "erase", [Opts.input_coverage] + GLOBAL_ARGS, + "erase", [Opts.input_datafile] + GLOBAL_ARGS, description="Erase previously collected coverage data.", ), @@ -484,7 +495,7 @@ CMDS = { Opts.include, Opts.module, Opts.omit, - Opts.output_coverage, + Opts.output_datafile, Opts.pylib, Opts.parallel_mode, Opts.source, @@ -607,11 +618,9 @@ 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_file=options.data_file or DEFAULT_DATAFILE, data_suffix=options.parallel_mode, cover_pylib=options.pylib, timid=options.timid, diff --git a/doc/cmd.rst b/doc/cmd.rst index 5bb0bd34..cba10065 100644 --- a/doc/cmd.rst +++ b/doc/cmd.rst @@ -142,11 +142,13 @@ There are many options: path, to be run as 'python -m' would run it. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. + --data-file=OUTFILE Write the recorded coverage data to this file. + Defaults to '.coverage'. [env: COVERAGE_FILE] -L, --pylib Measure coverage even inside the Python installed library, which isn't done by default. -p, --parallel-mode Append the machine name, process id and random number - to the .coverage data file name to simplify collecting - data from many processes. + to the data file name to simplify collecting data from + many processes. --source=SRC1,SRC2,... A list of directories or importable names of code to measure. @@ -158,7 +160,7 @@ There are many options: --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: bf76ace21288ca9d3c558ccd5fb82b08) +.. [[[end]]] (checksum: 3ec48d96422f8b3aed3cf5a8b223891f) If you want :ref:`branch coverage <branch>` measurement, use the ``--branch`` flag. Otherwise only statement coverage is measured. @@ -387,16 +389,20 @@ want to keep those files, use the ``--keep`` command-line option. directory are combined. Options: - -a, --append Append coverage data to .coverage, otherwise it starts - clean each time. - --keep Keep original coverage files, otherwise they are deleted. - -q, --quiet Don't print messages about what is happening. - --debug=OPTS Debug options, separated by commas. [env: COVERAGE_DEBUG] - -h, --help Get help on this command. - --rcfile=RCFILE Specify configuration file. By default '.coveragerc', - 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. - [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: ddd34bbd27ab1fda8dabce80e4d67795) + -a, --append Append coverage data to .coverage, otherwise it starts + clean each time. + --keep Keep original coverage files, otherwise they are + deleted. + -q, --quiet Don't print messages about what is happening. + --data-file=DATAFILE Base name of the data files to combine and write. + Defaults to '.coverage'. [env: COVERAGE_FILE] + --debug=OPTS Debug options, separated by commas. [env: + COVERAGE_DEBUG] + -h, --help Get help on this command. + --rcfile=RCFILE Specify configuration file. By default '.coveragerc', + 'setup.cfg', 'tox.ini', and 'pyproject.toml' are + tried. [env: COVERAGE_RCFILE] +.. [[[end]]] (checksum: 6cba18a0531f9d2f7af67e472b96eb6b) .. _cmd_erase: @@ -415,12 +421,15 @@ To erase the collected data, use the **erase** command: Erase previously collected coverage data. Options: - --debug=OPTS Debug options, separated by commas. [env: COVERAGE_DEBUG] - -h, --help Get help on this command. - --rcfile=RCFILE Specify configuration file. By default '.coveragerc', - 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. - [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: 27f64e800a037c7e8f90289affdd5f13) + --data-file=INFILE Read coverage data for report generation from this file. + Defaults to '.coverage'. [env: COVERAGE_FILE] + --debug=OPTS Debug options, separated by commas. [env: + COVERAGE_DEBUG] + -h, --help Get help on this command. + --rcfile=RCFILE Specify configuration file. By default '.coveragerc', + 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. + [env: COVERAGE_RCFILE] +.. [[[end]]] (checksum: e3dec8ef7687d3525682904340e8cf54) If your configuration file indicates parallel data collection, **erase** will remove all of the data files. @@ -505,13 +514,15 @@ as a percentage. --skip-covered Skip files with 100% coverage. --no-skip-covered Disable --skip-covered. --skip-empty Skip files with no code. + --data-file=INFILE Read coverage data for report generation from this + file. Defaults to '.coverage'. [env: COVERAGE_FILE] --debug=OPTS Debug options, separated by commas. [env: COVERAGE_DEBUG] -h, --help Get help on this command. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: e5e77534929d2579f9d022227ef97313) +.. [[[end]]] (checksum: 97565fdb6f1eefbeeb12d56151fa5e63) The ``-m`` flag also shows the line numbers of missing statements:: @@ -619,13 +630,15 @@ Click the keyboard icon in the upper right to see the complete list. --no-skip-covered Disable --skip-covered. --skip-empty Skip files with no code. --title=TITLE A text string to use as the title on the HTML. + --data-file=INFILE Read coverage data for report generation from this + file. Defaults to '.coverage'. [env: COVERAGE_FILE] --debug=OPTS Debug options, separated by commas. [env: COVERAGE_DEBUG] -h, --help Get help on this command. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: 75eda57d99b6c7b736f8ab2d60cc765d) +.. [[[end]]] (checksum: e3208f3b38a44ca81e0235e867f4fd1c) The title of the report can be set with the ``title`` setting in the ``[html]`` section of the configuration file, or the ``--title`` switch on @@ -691,13 +704,15 @@ compatible with `Cobertura`_. 'coverage.xml' -q, --quiet Don't print messages about what is happening. --skip-empty Skip files with no code. + --data-file=INFILE Read coverage data for report generation from this + file. Defaults to '.coverage'. [env: COVERAGE_FILE] --debug=OPTS Debug options, separated by commas. [env: COVERAGE_DEBUG] -h, --help Get help on this command. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: 7f5bcdcacbd60e32514201f24c56c17f) +.. [[[end]]] (checksum: 3dc4450c0a723109f987c4b6f968be43) You can specify the name of the output file with the ``-o`` switch. @@ -776,13 +791,15 @@ The **json** command writes coverage data to a "coverage.json" file. --pretty-print Format the JSON for human readers. -q, --quiet Don't print messages about what is happening. --show-contexts Show contexts for covered lines. + --data-file=INFILE Read coverage data for report generation from this + file. Defaults to '.coverage'. [env: COVERAGE_FILE] --debug=OPTS Debug options, separated by commas. [env: COVERAGE_DEBUG] -h, --help Get help on this command. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: 6fbe1ca09a8f0379a5e1794d8ac14e79) +.. [[[end]]] (checksum: fdc9af899380fbb78599d08a70e564fc) You can specify the name of the output file with the ``-o`` switch. The JSON can be nicely formatted by specifying the ``--pretty-print`` switch. @@ -880,13 +897,15 @@ For example:: quoted. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. + --data-file=INFILE Read coverage data for report generation from this + file. Defaults to '.coverage'. [env: COVERAGE_FILE] --debug=OPTS Debug options, separated by commas. [env: COVERAGE_DEBUG] -h, --help Get help on this command. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: 8c3175a256f38215016d03b66de23d5b) +.. [[[end]]] (checksum: aa41bad1cd4c08efc3276b5dca01dea3) Other common reporting options are described above in :ref:`cmd_reporting`. |