userver
C++ Async Framework
Loading...
Searching...
No Matches
testpoint.py
1
"""
2
Testpoints support for the server.
3
"""
4
5
# pylint: disable=redefined-outer-name
6
import
typing
7
8
import
pytest
9
10
USERVER_CONFIG_HOOKS = [
'userver_config_testpoint'
]
11
12
13
class
BaseError
(Exception):
14
pass
15
16
17
class
UnregisteredTestpointError
(
BaseError
):
18
pass
19
20
21
class
TestpointControl
:
22
def
__init__(self):
23
self.enabled_testpoints: typing.FrozenSet[str] = frozenset()
24
25
26
DISABLED_ERROR =
"""Access to {opname!r} on unregistered testpoint {name}
27
28
Use `await service_client.update_server_state()` to explicitly sync testpoints
29
state.
30
"""
31
32
33
@pytest.fixture
34
def
testpoint_control():
35
return
TestpointControl
()
36
37
38
@pytest.fixture
39
def
testpoint_checker_factory(testpoint_control):
40
def
create_checker(name):
41
def
checker(opname):
42
if
name
not
in
testpoint_control.enabled_testpoints:
43
raise
UnregisteredTestpointError
(
44
DISABLED_ERROR.format(opname=opname, name=name),
45
)
46
47
return
checker
48
49
return
create_checker
50
51
52
@pytest.fixture(scope='session')
53
def
userver_config_testpoint
(mockserver_info):
54
"""
55
Returns a function that adjusts the static configuration file for
56
the testsuite.
57
Sets the `tests-control.skip-unregistered-testpoints` to `True`.
58
59
@ingroup userver_testsuite_fixtures
60
"""
61
62
def
_patch_config(config_yaml, config_vars):
63
components = config_yaml[
'components_manager'
][
'components'
]
64
tests_control = components.get(
'tests-control'
)
65
if
tests_control:
66
tests_control[
'skip-unregistered-testpoints'
] =
True
67
68
return
_patch_config
testsuite
pytest_plugins
pytest_userver
plugins
testpoint.py
Generated on Wed May 15 2024 22:31:38 for userver by
Doxygen
1.10.0