diff options
-rw-r--r-- | coverage/collector.py | 18 | ||||
-rw-r--r-- | coverage/control.py | 6 |
2 files changed, 18 insertions, 6 deletions
diff --git a/coverage/collector.py b/coverage/collector.py index fa3eaaa4..db8373a1 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -99,6 +99,7 @@ class Collector(object): self.warn = warn self.branch = branch self.threading = None + self.covdata = None self.origin = short_stack() @@ -160,6 +161,10 @@ class Collector(object): def __repr__(self): return "<Collector at 0x%x: %s>" % (id(self), self.tracer_name()) + def use_data(self, covdata): + """Use `covdata` for recording data.""" + self.covdata = covdata + def tracer_name(self): """Return the class name of the tracer we're using.""" return self._trace_class.__name__ @@ -378,8 +383,11 @@ class Collector(object): except KeyError: return self.abs_file_cache.setdefault(key, abs_file(filename)) - def save_data(self, covdata): - """Save the collected data to a `CoverageData`. + def flush_data(self): + """Save the collected data to our associated `CoverageData`. + + Data may have also been saved along the way. This forces the + last of the data to be saved. Returns True if there was data to save, False if not. """ @@ -406,10 +414,10 @@ class Collector(object): return dict((self.cached_abs_file(k), v) for k, v in items) if self.branch: - covdata.add_arcs(abs_file_dict(self.data)) + self.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)) + self.covdata.add_lines(abs_file_dict(self.data)) + self.covdata.add_file_tracers(abs_file_dict(self.file_tracers)) if self.wtw: # Just a hack, so just hack it. diff --git a/coverage/control.py b/coverage/control.py index cdbd721f..ca0843d7 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -335,6 +335,7 @@ class Coverage(object): def _init_for_start(self): """Initialization for start()""" + # Construct the collector. concurrency = self.config.concurrency or [] if "multiprocessing" in concurrency: if not patch_multiprocessing: @@ -400,6 +401,9 @@ class Coverage(object): debug=self._debug, ) + if self._collector is not None: + self._collector.use_data(self._data) + def start(self): """Start measuring code coverage. @@ -564,7 +568,7 @@ class Coverage(object): self._init_data(suffix=None) self._post_init() - if self._collector and self._collector.save_data(self._data): + if self._collector and self._collector.flush_data(): self._post_save_work() return self._data |