Skip to content

Commit 2bd9645

Browse files
disable timeouts when debugger is active
pytest-dev/pytest-asyncio#216 (comment) > The PR is not complete until timeout disabling on debugging is > implemented, as in pytest-timeout. > Otherwise, any tests debug session ends with TimeoutError quickly. > I'm not sure is it worth to copy-paste the whole implementation > from pytest-timeout plugin? > Maybe adding timeout_setup()/timeout_teardown() hooks for > implementing them in pytest-asyncio makes the code easier and stablier? > Should take time for experimenting. > - asvetlov
1 parent b2ea526 commit 2bd9645

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

backend/tests/conftest.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
import inspect
5+
import sys
56
from typing import Any, Callable, Coroutine, Optional, TypeVar
67

78
import pytest
@@ -49,11 +50,16 @@ def pytest_runtest_call(item: Any) -> Any:
4950
async_test_func: Callable[[], Coroutine[Any, Any, Any]] = test_func
5051

5152
async def wrapped(*args: object, **kwargs: object) -> None:
52-
try:
53-
async with asyncio.timeout(time_limit):
54-
await async_test_func(*args, **kwargs)
55-
except asyncio.TimeoutError as exc:
56-
raise AsyncioTimeLimitExceeded(time_limit) from exc
53+
# https://stackoverflow.com/a/60364406
54+
# do not put time limit if running in debugger
55+
if "pdb" in sys.modules:
56+
await async_test_func(*args, **kwargs)
57+
else:
58+
try:
59+
async with asyncio.timeout(time_limit):
60+
await async_test_func(*args, **kwargs)
61+
except asyncio.TimeoutError as exc:
62+
raise AsyncioTimeLimitExceeded(time_limit) from exc
5763

5864
item.obj = wrapped
5965
yield

0 commit comments

Comments
 (0)