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