userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
asyncexc.py
1
"""
2
Async exceptions handler.
3
4
Handle excpetions in background coroutines.
5
"""
6
7
import
pytest
8
9
from
testsuite.utils
import
traceback
10
11
12
class
BaseError
(Exception):
13
pass
14
15
16
class
BackgroundExceptionError
(
BaseError
):
17
pass
18
19
20
__tracebackhide__ = traceback.hide(BaseError)
21
22
23
@pytest.fixture
24
def
_asyncexc():
25
errors: list[Exception] = []
26
try
:
27
yield
errors
28
finally
:
29
_raise_if_any(errors)
30
31
32
@pytest.fixture
33
def
asyncexc_append
(_asyncexc):
34
"""Register background exception.
35
36
@ingroup userver_testsuite_fixtures
37
Part of the [yandex-taxi-testsuite](https://github.com/yandex/yandex-taxi-testsuite/blob/develop/testsuite/plugins/asyncexc.py#L33)
38
"""
39
return
_asyncexc.append
40
41
42
@pytest.fixture
43
def
asyncexc_check
(_asyncexc):
44
"""Raise in case there are background exceptions.
45
46
@ingroup userver_testsuite_fixtures
47
Part of the [yandex-taxi-testsuite](https://github.com/yandex/yandex-taxi-testsuite/blob/develop/testsuite/plugins/asyncexc.py#L39)
48
"""
49
50
def
check():
51
_raise_if_any(_asyncexc)
52
53
return
check
54
55
56
def
_raise_if_any(errors):
57
if
not
errors:
58
return
59
errors = _clear_and_copy(errors)
60
for
exc
in
errors:
61
raise
BackgroundExceptionError
(
62
f
'There were {len(errors)} background exceptions'
63
f
', showing the first one'
,
64
)
from
exc
65
66
67
def
_clear_and_copy(errors):
68
copy = errors[:]
69
errors.clear()
70
return
copy
en
testsuite
plugins
asyncexc.py
Generated on
for userver by
Doxygen
1.17.0