summaryrefslogtreecommitdiff
path: root/coverage/control.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/control.py')
-rw-r--r--coverage/control.py16
1 files changed, 16 insertions, 0 deletions
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()