Skip to content

Commit

Permalink
move suite timeout to pytest_runtest_protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Okken authored and flub committed Mar 7, 2024
1 parent cc3f27a commit 79dea97
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions pytest_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ def pytest_runtest_protocol(item):
if is_timeout and settings.func_only is False:
hooks.pytest_timeout_cancel_timer(item=item)

# check suite timeout
expire_time = item.session.config.stash[SUITE_TIMEOUT_KEY]
if expire_time and (expire_time < time.time()):
timeout = item.session.config.getoption("--suite-timeout")
item.session.shouldfail = f"suite-timeout: {timeout} sec exceeded"


@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(item):
Expand Down Expand Up @@ -538,15 +544,3 @@ def dump_stacks(terminal):
thread_name = "<unknown>"
terminal.sep("~", title="Stack of %s (%s)" % (thread_name, thread_ident))
terminal.write("".join(traceback.format_stack(frame)))


@pytest.hookimpl(tryfirst=True)
def pytest_runtest_makereport(item, call):
# only need to check timeout once, at the end, after teardown
if call.when == "teardown":
session = item.session
config = session.config
expire_time = config.stash[SUITE_TIMEOUT_KEY]
if expire_time and (expire_time < time.time()):
timeout = config.getoption("--suite-timeout")
session.shouldfail = f"suite-timeout: {timeout} sec exceeded"

0 comments on commit 79dea97

Please sign in to comment.