本文整理汇总了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,
)
示例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
示例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)
示例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
示例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
示例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")
示例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")
示例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")