|
16 | 16 |
|
17 | 17 |
|
18 | 18 | def pytest_addoption(parser: Parser) -> None:
|
19 |
| - help = ( |
| 19 | + help_timeout = ( |
20 | 20 | "Dump the traceback of all threads if a test takes "
|
21 | 21 | "more than TIMEOUT seconds to finish"
|
22 | 22 | )
|
23 |
| - parser.addini("faulthandler_timeout", help, default=0.0) |
| 23 | + help_exit_on_timeout = ( |
| 24 | + "Exit the test process if a test takes more than " |
| 25 | + "faulthandler_timeout seconds to finish" |
| 26 | + ) |
| 27 | + parser.addini("faulthandler_timeout", help_timeout, default=0.0) |
| 28 | + parser.addini( |
| 29 | + "faulthandler_exit_on_timeout", help_exit_on_timeout, type="bool", default=False |
| 30 | + ) |
24 | 31 |
|
25 | 32 |
|
26 | 33 | def pytest_configure(config: Config) -> None:
|
@@ -72,14 +79,21 @@ def get_timeout_config_value(config: Config) -> float:
|
72 | 79 | return float(config.getini("faulthandler_timeout") or 0.0)
|
73 | 80 |
|
74 | 81 |
|
| 82 | +def get_exit_on_timeout_config_value(config: Config) -> bool: |
| 83 | + exit_on_timeout = config.getini("faulthandler_exit_on_timeout") |
| 84 | + assert isinstance(exit_on_timeout, bool) |
| 85 | + return exit_on_timeout |
| 86 | + |
| 87 | + |
75 | 88 | @pytest.hookimpl(wrapper=True, trylast=True)
|
76 | 89 | def pytest_runtest_protocol(item: Item) -> Generator[None, object, object]:
|
77 | 90 | timeout = get_timeout_config_value(item.config)
|
| 91 | + exit_on_timeout = get_exit_on_timeout_config_value(item.config) |
78 | 92 | if timeout > 0:
|
79 | 93 | import faulthandler
|
80 | 94 |
|
81 | 95 | stderr = item.config.stash[fault_handler_stderr_fd_key]
|
82 |
| - faulthandler.dump_traceback_later(timeout, file=stderr) |
| 96 | + faulthandler.dump_traceback_later(timeout, file=stderr, exit=exit_on_timeout) |
83 | 97 | try:
|
84 | 98 | return (yield)
|
85 | 99 | finally:
|
|
0 commit comments