19
19
20
20
21
21
__all__ = ("is_debugging" , "Settings" )
22
+ suite_timeout_key = pytest .StashKey [float ]()
22
23
23
24
24
25
HAVE_SIGALRM = hasattr (signal , "SIGALRM" )
45
46
will be interrupted by the timeout.
46
47
""" .strip ()
47
48
SUITE_TIMEOUT_DESC = """
48
- Timeout in minutes for entire suite. Default is None which
49
+ Timeout in seconds for entire suite. Default is None which
49
50
means no timeout. Timeout is checked between tests, and will not interrupt a test
50
- in progress. Can be specified as a float for partial minutes.
51
+ in progress.
51
52
""" .strip ()
52
53
53
54
# bdb covers pdb, ipdb, and possibly others
@@ -91,7 +92,7 @@ def pytest_addoption(parser):
91
92
dest = "suite_timeout" ,
92
93
default = None ,
93
94
type = float ,
94
- metavar = "minutes " ,
95
+ metavar = "SECONDS " ,
95
96
help = SUITE_TIMEOUT_DESC ,
96
97
)
97
98
parser .addini ("timeout" , TIMEOUT_DESC )
@@ -162,10 +163,12 @@ def pytest_configure(config):
162
163
config ._env_timeout_func_only = settings .func_only
163
164
config ._env_timeout_disable_debugger_detection = settings .disable_debugger_detection
164
165
165
- _suite_timeout_minutes = config .getoption ("--suite-timeout" )
166
- if _suite_timeout_minutes :
167
- _suite_expire_time = time .time () + (_suite_timeout_minutes * 60 )
168
-
166
+ timeout = config .getoption ("--suite-timeout" )
167
+ if timeout is not None :
168
+ expire_time = time .time () + timeout
169
+ else :
170
+ expire_time = 0
171
+ config .stash [suite_timeout_key ] = expire_time
169
172
170
173
171
174
@pytest .hookimpl (hookwrapper = True )
@@ -533,7 +536,10 @@ def dump_stacks(terminal):
533
536
terminal .write ("" .join (traceback .format_stack (frame )))
534
537
535
538
536
- def pytest_runtest_logfinish (nodeid , location ):
537
- if _suite_expire_time and _suite_expire_time < time .time ():
538
- pytest .exit (f"suite-timeout: { _suite_timeout_minutes } minutes exceeded" ,
539
- returncode = 0 )
539
+ def pytest_runtest_makereport (item , call ):
540
+ session = item .session
541
+ config = session .config
542
+ expire_time = config .stash [suite_timeout_key ]
543
+ if expire_time and (expire_time < time .time ()):
544
+ timeout = config .getoption ("--suite-timeout" )
545
+ session .shouldfail = f"suite-timeout: { timeout } sec exceeded"
0 commit comments