summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/collector.py21
-rw-r--r--coverage/ctracer/tracer.c4
-rw-r--r--coverage/ctracer/util.h2
3 files changed, 17 insertions, 10 deletions
diff --git a/coverage/collector.py b/coverage/collector.py
index fff4f6ad..aabf10b7 100644
--- a/coverage/collector.py
+++ b/coverage/collector.py
@@ -121,6 +121,10 @@ class Collector(object):
"Couldn't trace with concurrency=%s, the module isn't installed." % concurrency
)
+ # Who-Tests-What is just a hack at the moment, so turn it on with an
+ # environment variable.
+ self.wtw = int(os.getenv('COVERAGE_WTW', 0))
+
self.reset()
if timid:
@@ -215,10 +219,11 @@ class Collector(object):
tracer.threading = self.threading
if hasattr(tracer, 'check_include'):
tracer.check_include = self.check_include
- if hasattr(tracer, 'should_start_context'):
- tracer.should_start_context = should_start_context
- if hasattr(tracer, 'switch_context'):
- tracer.switch_context = self.switch_context
+ if self.wtw:
+ if hasattr(tracer, 'should_start_context'):
+ tracer.should_start_context = should_start_context
+ if hasattr(tracer, 'switch_context'):
+ tracer.switch_context = self.switch_context
fn = tracer.start()
self.tracers.append(tracer)
@@ -321,7 +326,6 @@ class Collector(object):
self._start_tracer()
def switch_context(self, new_context):
- print("** Switching to {!r}".format(new_context))
data = self.contexts.setdefault(new_context, {})
for tracer in self.tracers:
tracer.data = data
@@ -336,11 +340,16 @@ class Collector(object):
"""Return a dict like d, but with keys modified by `abs_file`."""
return dict((abs_file(k), v) for k, v in iitems(d))
- import pprint; pprint.pprint(self.contexts)
if self.branch:
covdata.add_arcs(abs_file_dict(self.data))
else:
covdata.add_lines(abs_file_dict(self.data))
covdata.add_file_tracers(abs_file_dict(self.file_tracers))
+ if self.wtw:
+ # Just a hack, so just hack it.
+ import pprint
+ with open("coverage_wtw.py", "w") as wtw_out:
+ pprint.pprint(self.contexts, wtw_out)
+
self.reset()
diff --git a/coverage/ctracer/tracer.c b/coverage/ctracer/tracer.c
index 42587b1e..3266ff2f 100644
--- a/coverage/ctracer/tracer.c
+++ b/coverage/ctracer/tracer.c
@@ -353,7 +353,7 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame)
self->pdata_stack->stack[self->pdata_stack->depth] = self->cur_entry;
/* See if this frame begins a new context. */
- if (self->should_start_context != Py_None && self->context == Py_None) {
+ if (self->should_start_context && self->context == Py_None) {
PyObject * context;
/* We're looking for our context, ask should_start_context if this is the start. */
STATS( self->stats.start_context_calls++; )
@@ -1067,7 +1067,7 @@ CTracer_members[] = {
{ "should_start_context", T_OBJECT, offsetof(CTracer, should_start_context), 0,
PyDoc_STR("Function for starting contexts.") },
- { "switch_context", T_OBJECT, offsetof(CTracer, switch_context), 0,
+ { "switch_context", T_OBJECT, offsetof(CTracer, switch_context), 0,
PyDoc_STR("Function for switch to a new context.") },
{ NULL }
diff --git a/coverage/ctracer/util.h b/coverage/ctracer/util.h
index 2f962c3f..ad8f49d6 100644
--- a/coverage/ctracer/util.h
+++ b/coverage/ctracer/util.h
@@ -11,8 +11,6 @@
#undef TRACE_LOG /* Define to log our bookkeeping. */
#undef COLLECT_STATS /* Collect counters: stats are printed when tracer is stopped. */
-#define COLLECT_STATS 1
-
/* Py 2.x and 3.x compatibility */
#if PY_MAJOR_VERSION >= 3