Skip to content

Commit 58a8aff

Browse files
committed
Wrap yield's in try/finally
Signed-off-by: Pedro Algarvio <[email protected]>
1 parent 027ae81 commit 58a8aff

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

pytest_timeout.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,11 @@ def pytest_runtest_protocol(item):
157157
is_timeout = settings.timeout is not None and settings.timeout > 0
158158
if is_timeout and settings.func_only is False:
159159
hooks.pytest_timeout_set_timer(item=item, settings=settings)
160-
yield
161-
if is_timeout and settings.func_only is False:
162-
hooks.pytest_timeout_cancel_timer(item=item)
160+
try:
161+
yield
162+
finally:
163+
if is_timeout and settings.func_only is False:
164+
hooks.pytest_timeout_cancel_timer(item=item)
163165

164166

165167
@pytest.hookimpl(hookwrapper=True)
@@ -174,9 +176,11 @@ def pytest_runtest_call(item):
174176
is_timeout = settings.timeout is not None and settings.timeout > 0
175177
if is_timeout and settings.func_only is True:
176178
hooks.pytest_timeout_set_timer(item=item, settings=settings)
177-
yield
178-
if is_timeout and settings.func_only is True:
179-
hooks.pytest_timeout_cancel_timer(item=item)
179+
try:
180+
yield
181+
finally:
182+
if is_timeout and settings.func_only is True:
183+
hooks.pytest_timeout_cancel_timer(item=item)
180184

181185

182186
@pytest.hookimpl(tryfirst=True)

0 commit comments

Comments
 (0)