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

Function test_timeout_and_exit

testing/test_faulthandler.py:127–155  ·  view source on GitHub ↗

Test option to force exit pytest process after a certain timeout.

(pytester: Pytester, exit_on_timeout: bool)

Source from the content-addressed store, hash-verified

125)
126@pytest.mark.parametrize("exit_on_timeout", [True, False])
127def test_timeout_and_exit(pytester: Pytester, exit_on_timeout: bool) -> None:
128 """Test option to force exit pytest process after a certain timeout."""
129 pytester.makepyfile(
130 """
131 import os, time
132 def test_long_sleep_and_raise():
133 time.sleep(1 if "CI" in os.environ else 0.1)
134 raise AssertionError(
135 "This test should have been interrupted before reaching this point."
136 )
137 """
138 )
139 pytester.makeini(
140 f"""
141 [pytest]
142 faulthandler_timeout = 0.01
143 faulthandler_exit_on_timeout = {"true" if exit_on_timeout else "false"}
144 """
145 )
146 result = pytester.runpytest_subprocess()
147 tb_output = "most recent call first"
148 result.stderr.fnmatch_lines([f"*{tb_output}*"])
149 if exit_on_timeout:
150 result.stdout.no_fnmatch_line("*1 failed*")
151 result.stdout.no_fnmatch_line("*AssertionError*")
152 else:
153 result.stdout.fnmatch_lines(["*1 failed*"])
154 result.stdout.fnmatch_lines(["*AssertionError*"])
155 assert result.ret == 1
156
157
158@pytest.mark.parametrize("hook_name", ["pytest_enter_pdb", "pytest_exception_interact"])

Callers

nothing calls this directly

Calls 5

fnmatch_linesMethod · 0.80
no_fnmatch_lineMethod · 0.80
makepyfileMethod · 0.45
makeiniMethod · 0.45
runpytest_subprocessMethod · 0.45

Tested by

no test coverage detected