当前位置: 首页>>代码示例>>Python>>正文


Python Collector.switch_context方法代码示例

本文整理汇总了Python中coverage.collector.Collector.switch_context方法的典型用法代码示例。如果您正苦于以下问题:Python Collector.switch_context方法的具体用法?Python Collector.switch_context怎么用?Python Collector.switch_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coverage.collector.Collector的用法示例。


在下文中一共展示了Collector.switch_context方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Coverage

# 需要导入模块: from coverage.collector import Collector [as 别名]
# 或者: from coverage.collector.Collector import switch_context [as 别名]

#.........这里部分代码省略.........
        self._collector.start()
        self._started = True

    def stop(self):
        """Stop measuring code coverage."""
        if self._started:
            self._collector.stop()
        self._started = False

    def _atexit(self):
        """Clean up on process shutdown."""
        if self._debug.should("process"):
            self._debug.write("atexit: {0!r}".format(self))
        if self._started:
            self.stop()
        if self._auto_save:
            self.save()

    def erase(self):
        """Erase previously-collected coverage data.

        This removes the in-memory data collected in this session as well as
        discarding the data file.

        """
        self._init()
        self._post_init()
        if self._collector:
            self._collector.reset()
        self._init_data(suffix=None)
        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.  If a :ref:`static context <static_contexts>` is in
        use, the static and dynamic context labels will be joined together with
        a pipe character.

        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()
        setattr(self.config, which + "_list", [])
        self._exclude_regex_stale()

    def exclude(self, regex, which='exclude'):
        """Exclude source lines from execution consideration.

        A number of lists of regular expressions are maintained.  Each list
        selects lines that are treated differently during reporting.

        `which` determines which list is modified.  The "exclude" list selects
        lines that are not considered executable at all.  The "partial" list
        indicates lines with branches that are not taken.
开发者ID:hugovk,项目名称:coveragepy,代码行数:70,代码来源:control.py


注:本文中的coverage.collector.Collector.switch_context方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。