diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-06-25 08:35:00 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-06-25 08:35:00 -0400 |
commit | 34cdb26ab14c9fe62d782fe4dffa9472a2cf4303 (patch) | |
tree | fd116ee3c1d1b19d74f04e1455334d5be849f32b | |
parent | e84697e061a640ac398b1200d0ebaa96b7ee2e39 (diff) | |
download | python-coveragepy-34cdb26ab14c9fe62d782fe4dffa9472a2cf4303.tar.gz |
Combine no longer appends by default
Combine used to always load an existing .coverage file. This lead to confusing
results and extra tox-clean steps. Now the default is to not load the existing
file, though a new --append switch on coverage combine gets you that behavior
if you need it.
This also pointed up an issue with concurrency=multiprocessing, which is that
the child processes automatically used parallel=True, but the parent process
did not. Now concurrency=multiprocessing implies parallel=True.
-rw-r--r-- | CHANGES.rst | 8 | ||||
-rw-r--r-- | coverage/cmdline.py | 7 | ||||
-rw-r--r-- | coverage/control.py | 3 | ||||
-rw-r--r-- | doc/cmd.rst | 5 | ||||
-rw-r--r-- | tests/test_cmdline.py | 9 | ||||
-rw-r--r-- | tests/test_process.py | 2 |
6 files changed, 28 insertions, 6 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index a231a69..fcb61a9 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,14 @@ Change history for Coverage.py Unreleased ---------- +- BACKWARD INCOMPATIBILITY: the ``coverage combine`` command now ignores an + existing ``.coverage`` data file. It used to include that file in its + combining. This caused confusing results, and extra tox "clean" steps. If + you want the old behavior, use the new ``coverage combine --append`` option. + +- Using ``--concurrency=multiprocessing`` now implies ``--parallel`` so that + the main program is measured similarly to the sub-processes. + - When using `automatic subprocess measurement`_, running coverage commands would create spurious data files. This is now fixed, thanks to diagnosis and testing by Dan Riti. Closes `issue 492`_. diff --git a/coverage/cmdline.py b/coverage/cmdline.py index e2b79fe..9ff39f4 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -274,7 +274,9 @@ CMDS = { 'combine': CmdOptionParser( "combine", - GLOBAL_ARGS, + [ + Opts.append, + ] + GLOBAL_ARGS, usage="<path1> <path2> ... <pathN>", description=( "Combine data from multiple coverage files collected " @@ -484,7 +486,8 @@ class CoverageScript(object): return self.do_run(options, args) elif options.action == "combine": - self.coverage.load() + if options.append: + self.coverage.load() data_dirs = args or None self.coverage.combine(data_dirs) self.coverage.save() diff --git a/coverage/control.py b/coverage/control.py index 2f2989c..f350b3d 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -247,6 +247,9 @@ class Coverage(object): if concurrency == "multiprocessing": patch_multiprocessing() concurrency = None + # Multi-processing uses parallel for the subprocesses, so also use + # it for the main process. + self.config.parallel = True self.collector = Collector( should_trace=self._should_trace, diff --git a/doc/cmd.rst b/doc/cmd.rst index f77738b..90e2105 100644 --- a/doc/cmd.rst +++ b/doc/cmd.rst @@ -212,6 +212,11 @@ suffix. Here are some examples of data files that can be combined:: .coverage.20120807T212300 .coverage.last_good_run.ok +An existing combined data file is ignored and re-written. If you want to use +**combine** to accumulate results into the .coverage data file over a number of +runs, use the ``--append`` switch on the **combine** command. This behavior +was the default before version 4.2. + The ``run --parallel-mode`` switch automatically creates separate data files for each run which can be combined later. The file names include the machine name, the process id, and a random number:: diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 8e2840b..795a01f 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -190,6 +190,12 @@ class CmdLineTest(BaseCmdLineTest): # coverage combine with args self.cmd_executes("combine datadir1", """\ .coverage() + .combine(["datadir1"]) + .save() + """) + # coverage combine, appending + self.cmd_executes("combine --append datadir1", """\ + .coverage() .load() .combine(["datadir1"]) .save() @@ -197,7 +203,6 @@ class CmdLineTest(BaseCmdLineTest): # coverage combine without args self.cmd_executes("combine", """\ .coverage() - .load() .combine(None) .save() """) @@ -206,13 +211,11 @@ class CmdLineTest(BaseCmdLineTest): # https://bitbucket.org/ned/coveragepy/issues/385/coverage-combine-doesnt-work-with-rcfile self.cmd_executes("combine --rcfile cov.ini", """\ .coverage(config_file='cov.ini') - .load() .combine(None) .save() """) self.cmd_executes("combine --rcfile cov.ini data1 data2/more", """\ .coverage(config_file='cov.ini') - .load() .combine(["data1", "data2/more"]) .save() """) diff --git a/tests/test_process.py b/tests/test_process.py index 5e0014e..328bd9e 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -150,7 +150,7 @@ class ProcessTest(CoverageTest): self.assertEqual(self.number_of_data_files(), 2) # Combine the parallel coverage data files into .coverage . - self.run_command("coverage combine") + self.run_command("coverage combine --append") self.assert_exists(".coverage") # After combining, there should be only the .coverage file. |