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


Python faulthandler.is_enabled方法代码示例

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


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

示例1: pytest_configure

# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import is_enabled [as 别名]
def pytest_configure(config: Config) -> None:
    import faulthandler

    if not faulthandler.is_enabled():
        # faulthhandler is not enabled, so install plugin that does the actual work
        # of enabling faulthandler before each test executes.
        config.pluginmanager.register(FaultHandlerHooks(), "faulthandler-hooks")
    else:
        from _pytest.warnings import _issue_warning_captured

        # Do not handle dumping to stderr if faulthandler is already enabled, so warn
        # users that the option is being ignored.
        timeout = FaultHandlerHooks.get_timeout_config_value(config)
        if timeout > 0:
            _issue_warning_captured(
                pytest.PytestConfigWarning(
                    "faulthandler module enabled before pytest configuration step, "
                    "'faulthandler_timeout' option ignored"
                ),
                config.hook,
                stacklevel=2,
            ) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:24,代码来源:faulthandler.py

示例2: test_is_enabled

# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import is_enabled [as 别名]
def test_is_enabled(self):
        orig_stderr = sys.stderr
        try:
            # regrtest may replace sys.stderr by io.StringIO object, but
            # faulthandler.enable() requires that sys.stderr has a fileno()
            # method
            sys.stderr = sys.__stderr__

            was_enabled = faulthandler.is_enabled()
            try:
                faulthandler.enable()
                self.assertTrue(faulthandler.is_enabled())
                faulthandler.disable()
                self.assertFalse(faulthandler.is_enabled())
            finally:
                if was_enabled:
                    faulthandler.enable()
                else:
                    faulthandler.disable()
        finally:
            sys.stderr = orig_stderr 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_faulthandler.py

示例3: pytest_configure

# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import is_enabled [as 别名]
def pytest_configure(config):
    import faulthandler

    # avoid trying to dup sys.stderr if faulthandler is already enabled
    if faulthandler.is_enabled():
        return

    stderr_fd_copy = os.dup(_get_stderr_fileno())
    config.fault_handler_stderr = os.fdopen(stderr_fd_copy, "w")
    faulthandler.enable(file=config.fault_handler_stderr) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:12,代码来源:faulthandler.py

示例4: test_disabled

# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import is_enabled [as 别名]
def test_disabled(testdir):
    """Test option to disable fault handler in the command line.
    """
    testdir.makepyfile(
        """
    import faulthandler
    def test_disabled():
        assert not faulthandler.is_enabled()
    """
    )
    result = testdir.runpytest_subprocess("-p", "no:faulthandler")
    result.stdout.fnmatch_lines(["*1 passed*"])
    assert result.ret == 0 
开发者ID:pytest-dev,项目名称:pytest,代码行数:15,代码来源:test_faulthandler.py

示例5: test_already_initialized

# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import is_enabled [as 别名]
def test_already_initialized(faulthandler_timeout, testdir):
    """Test for faulthandler being initialized earlier than pytest (#6575)"""
    testdir.makepyfile(
        """
        def test():
            import faulthandler
            assert faulthandler.is_enabled()
    """
    )
    result = testdir.run(
        sys.executable,
        "-X",
        "faulthandler",
        "-mpytest",
        testdir.tmpdir,
        "-o",
        "faulthandler_timeout={}".format(faulthandler_timeout),
    )
    # ensure warning is emitted if faulthandler_timeout is configured
    warning_line = "*faulthandler.py*faulthandler module enabled before*"
    if faulthandler_timeout > 0:
        result.stdout.fnmatch_lines(warning_line)
    else:
        result.stdout.no_fnmatch_line(warning_line)
    result.stdout.fnmatch_lines("*1 passed*")
    assert result.ret == 0 
开发者ID:pytest-dev,项目名称:pytest,代码行数:28,代码来源:test_faulthandler.py

示例6: test_disabled_by_default

# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import is_enabled [as 别名]
def test_disabled_by_default(self):
        # By default, the module should be disabled
        code = "import faulthandler; print(faulthandler.is_enabled())"
        args = filter(None, (sys.executable,
                             "-E" if sys.flags.ignore_environment else "",
                             "-c", code))
        env = os.environ.copy()
        env.pop("PYTHONFAULTHANDLER", None)
        # don't use assert_python_ok() because it always enables faulthandler
        output = subprocess.check_output(args, env=env)
        self.assertEqual(output.rstrip(), b"False") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:test_faulthandler.py

示例7: test_sys_xoptions

# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import is_enabled [as 别名]
def test_sys_xoptions(self):
        # Test python -X faulthandler
        code = "import faulthandler; print(faulthandler.is_enabled())"
        args = filter(None, (sys.executable,
                             "-E" if sys.flags.ignore_environment else "",
                             "-X", "faulthandler", "-c", code))
        env = os.environ.copy()
        env.pop("PYTHONFAULTHANDLER", None)
        # don't use assert_python_ok() because it always enables faulthandler
        output = subprocess.check_output(args, env=env)
        self.assertEqual(output.rstrip(), b"True") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:test_faulthandler.py

示例8: test_env_var

# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import is_enabled [as 别名]
def test_env_var(self):
        # empty env var
        code = "import faulthandler; print(faulthandler.is_enabled())"
        args = (sys.executable, "-c", code)
        env = os.environ.copy()
        env['PYTHONFAULTHANDLER'] = ''
        # don't use assert_python_ok() because it always enables faulthandler
        output = subprocess.check_output(args, env=env)
        self.assertEqual(output.rstrip(), b"False")

        # non-empty env var
        env = os.environ.copy()
        env['PYTHONFAULTHANDLER'] = '1'
        output = subprocess.check_output(args, env=env)
        self.assertEqual(output.rstrip(), b"True") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:test_faulthandler.py


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