summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-06-24 10:41:15 -0400
committerNed Batchelder <ned@nedbatchelder.com>2016-06-24 10:41:15 -0400
commite84697e061a640ac398b1200d0ebaa96b7ee2e39 (patch)
tree1093233e923635f6c460fd694a78856c2264908c /coverage
parent862e5ccdce7583eb2b9f5bd82f8e81cbd4c4a255 (diff)
downloadpython-coveragepy-e84697e061a640ac398b1200d0ebaa96b7ee2e39.tar.gz
Prevent subprocess measurement from measuring coverage commands. #492
Diffstat (limited to 'coverage')
-rw-r--r--coverage/control.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/coverage/control.py b/coverage/control.py
index 97d4625..2f2989c 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