Skip to content

Commit c6962b8

Browse files
okkenflub
authored andcommitted
describe session timeout better
1 parent a19403d commit c6962b8

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

README.rst

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,15 @@ function:
344344
Session Timeout
345345
===============
346346

347-
The above mentioned timeouts are all per test function. You can also set a
348-
session timeout in seconds. The following example shows a session timeout
349-
of 10 minutes (600 seconds)::
347+
The above mentioned timeouts are all per test function.
348+
The "per test function" timeouts will stop an individual test
349+
from taking too long. We may also want to limit the time of the entire
350+
set of tests running in one session. A session all of the tests
351+
that will be run with one invokation of pytest.
352+
353+
A session timeout is set with `--session-timeout` and is in seconds.
354+
355+
The following example shows a session timeout of 10 minutes (600 seconds)::
350356

351357
pytest --session-timeout=600
352358

@@ -357,14 +363,14 @@ You can also set the session timeout the pytest configuration file using the ``s
357363
[pytest]
358364
session_timeout = 600
359365
360-
Friendly timeouts
366+
Cooperative timeouts
361367
-----------------
362368

363-
Session timeouts are "friendly" timeouts. The plugin checks the session time at the end of
369+
Session timeouts are cooperative timeouts. The plugin checks the session time at the end of
364370
each test function, and stops further tests from running if the session timeout is exceeded.
365371

366-
Combining session and function
367-
------------------------------
372+
Combining session and function timeouts
373+
---------------------------------------
368374

369375
It works fine to combine both session and function timeouts.
370376
For example, to limit test functions to 5 seconds and the full session to 100 seconds::

test_pytest_timeout.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,9 @@ def test_foo():
611611

612612

613613
def test_session_timeout(pytester):
614-
# 2 tests, each with 0.5 sec timeouts
615-
# each using a fixture with 0.5 sec setup and 0.5 sec teardown
616-
# So about 1.5 seconds per test, ~3 sec total,
617-
# Therefore:
618-
# A timeout of 1.25 sec should happen during the teardown of the first test
619-
# and the second test should NOT be run
614+
# This is designed to timeout during hte first test to ensure
615+
# - the first test still runs to completion
616+
# - the second test is not started
620617
pytester.makepyfile(
621618
"""
622619
import time, pytest
@@ -636,7 +633,8 @@ def test_two(slow_setup_and_teardown):
636633
)
637634
result = pytester.runpytest_subprocess("--session-timeout", "2")
638635
result.stdout.fnmatch_lines(["*!! session-timeout: 2.0 sec exceeded !!!*"])
639-
result.assert_outcomes(passed=1)
636+
# This would be 2 passed if the second test was allowed to run
637+
result.assert_outcomes(passed=1)
640638

641639

642640
def test_ini_session_timeout(pytester):

0 commit comments

Comments
 (0)