當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。