diff options
-rw-r--r-- | CHANGES.rst | 6 | ||||
-rw-r--r-- | coverage/control.py | 18 | ||||
-rw-r--r-- | tests/test_process.py | 2 |
3 files changed, 22 insertions, 4 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index e8b58194..a231a69c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,10 @@ Change history for Coverage.py Unreleased ---------- +- 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`_. + - A new configuration option, ``report:sort``, controls what column of the text report is used to sort the rows. Thanks to Dan Wandschneider, this closes `issue 199`_. @@ -33,12 +37,14 @@ Unreleased - The `test_helpers` module has been moved into a separate pip-installable package: `unittest-mixins`_. +.. _automatic subprocess measurement: http://coverage.readthedocs.io/en/latest/subprocess.html .. _issue 199: https://bitbucket.org/ned/coveragepy/issues/199/add-a-way-to-sort-the-text-report .. _issue 231: https://bitbucket.org/ned/coveragepy/issues/231/various-default-behavior-in-report-phase .. _issue 298: https://bitbucket.org/ned/coveragepy/issues/298/show-in-html-report-that-the-columns-are .. _issue 396: https://bitbucket.org/ned/coveragepy/issues/396/coverage-xml-shouldnt-bail-out-on-parse .. _issue 454: https://bitbucket.org/ned/coveragepy/issues/454/coverage-debug-config-should-be .. _issue 478: https://bitbucket.org/ned/coveragepy/issues/478/help-shows-silly-program-name-when-running +.. _issue 492: https://bitbucket.org/ned/coveragepy/issues/492/subprocess-coverage-strange-detection-of .. _unittest-mixins: https://pypi.python.org/pypi/unittest-mixins diff --git a/coverage/control.py b/coverage/control.py index 97d46250..2f2989cb 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -192,6 +192,13 @@ class Coverage(object): # Have we measured some data and not harvested it? self._measured = False + # If we have sub-process measurement happening automatically, then we + # want any explicit creation of a Coverage object to mean, this process + # is already coverage-aware, so don't auto-measure it. By now, the + # auto-creation of a Coverage object has already happened. But we can + # find it and tell it not to save its data. + _prevent_sub_process_measurement() + def _init(self): """Set all the initial state. @@ -1185,15 +1192,22 @@ def process_startup(): # https://bitbucket.org/ned/coveragepy/issue/340/keyerror-subpy has more # details. - if hasattr(process_startup, "done"): + if hasattr(process_startup, "coverage"): # We've annotated this function before, so we must have already # started coverage.py in this process. Nothing to do. return None - process_startup.done = True cov = Coverage(config_file=cps, auto_data=True) + process_startup.coverage = cov cov.start() cov._warn_no_data = False cov._warn_unimported_source = False return cov + + +def _prevent_sub_process_measurement(): + """Stop any subprocess auto-measurement from writing data.""" + auto_created_coverage = getattr(process_startup, "coverage", None) + if auto_created_coverage is not None: + auto_created_coverage._auto_data = False diff --git a/tests/test_process.py b/tests/test_process.py index f1fa7f32..5e0014ef 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -13,7 +13,6 @@ import textwrap import coverage from coverage import env, CoverageData -from coverage.backunittest import unittest from coverage.misc import output_encoding from tests.coveragetest import CoverageTest @@ -1065,7 +1064,6 @@ class ProcessStartupTest(ProcessCoverageMixin, CoverageTest): data.read_file(".mycovdata") self.assertEqual(data.line_counts()['sub.py'], 2) - @unittest.expectedFailure def test_subprocess_with_pth_files_and_parallel(self): # pragma: not covered # https://bitbucket.org/ned/coveragepy/issues/492/subprocess-coverage-strange-detection-of if env.METACOV: |