diff options
author | Justas Sadzevičius <justas.sadzevicius@gmail.com> | 2019-04-28 20:00:24 +0300 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2019-04-28 13:00:24 -0400 |
commit | 0f682599ac6a1c0568b97dd1b392edce2d8d18df (patch) | |
tree | affce4cd983038d1a48e9e1277a1e6ca72b54bea /coverage/control.py | |
parent | ef1595a8cf1e231609106934b59dd8eab6fd7958 (diff) | |
download | python-coveragepy-git-0f682599ac6a1c0568b97dd1b392edce2d8d18df.tar.gz |
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
Diffstat (limited to 'coverage/control.py')
-rw-r--r-- | coverage/control.py | 16 |
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() |