From 0f682599ac6a1c0568b97dd1b392edce2d8d18df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Justas=20Sadzevi=C4=8Dius?= Date: Sun, 28 Apr 2019 20:00:24 +0300 Subject: Expose switch_context in coverage API (#782) * Expose switch_context in public API * Test switch_context * Helper method to get full paths to measured files * Get correct file paths on all OS * Note version that introduced this method --- coverage/control.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'coverage') diff --git a/coverage/control.py b/coverage/control.py index 9bcab844..ace3d8bf 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -483,6 +483,22 @@ class Coverage(object): self._data.erase(parallel=self.config.parallel) self._data = None + def switch_context(self, new_context): + """Switch to a new dynamic context. + + `new_context` is a string to use as the context label + for collected data. + + Coverage collection must be started already. + + .. versionadded:: 5.0 + """ + if not self._started: + raise CoverageException( # pragma: only jython + "Cannot switch context, coverage is not started" + ) + self._collector.switch_context(new_context) + def clear_exclude(self, which='exclude'): """Clear the exclude list.""" self._init() -- cgit v1.2.1