MCPcopy
hub / github.com/pytest-dev/pytest / test_timeout

Function test_timeout

testing/test_faulthandler.py:91–118  ·  view source on GitHub ↗

Test option to dump tracebacks after a certain timeout. If faulthandler is disabled, no traceback will be dumped.

(pytester: Pytester, enabled: bool)

Source from the content-addressed store, hash-verified

89 ],
90)
91def test_timeout(pytester: Pytester, enabled: bool) -> None:
92 """Test option to dump tracebacks after a certain timeout.
93
94 If faulthandler is disabled, no traceback will be dumped.
95 """
96 pytester.makepyfile(
97 """
98 import os, time
99 def test_timeout():
100 time.sleep(1 if "CI" in os.environ else 0.1)
101 """
102 )
103 pytester.makeini(
104 """
105 [pytest]
106 faulthandler_timeout = 0.01
107 """
108 )
109 args = ["-p", "no:faulthandler"] if not enabled else []
110
111 result = pytester.runpytest_subprocess(*args)
112 tb_output = "most recent call first"
113 if enabled:
114 result.stderr.fnmatch_lines([f"*{tb_output}*"])
115 else:
116 assert tb_output not in result.stderr.str()
117 result.stdout.fnmatch_lines(["*1 passed*"])
118 assert result.ret == 0
119
120
121@pytest.mark.keep_ci_var

Callers

nothing calls this directly

Calls 5

fnmatch_linesMethod · 0.80
strMethod · 0.80
makepyfileMethod · 0.45
makeiniMethod · 0.45
runpytest_subprocessMethod · 0.45

Tested by

no test coverage detected