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 typing
7
8import pytest
9
10USERVER_CONFIG_HOOKS = ['userver_config_testpoint']
11
12
13class BaseError(Exception):
14 pass
15
16
22 def __init__(self):
23 self.enabled_testpoints: typing.FrozenSet[str] = frozenset()
24
25
26DISABLED_ERROR = """Access to {opname!r} on unregistered testpoint {name}
27
28Use `await service_client.update_server_state()` to explicitly sync testpoints
29state.
30"""
31
32
33@pytest.fixture
34def testpoint_control():
35 return TestpointControl()
36
37
38@pytest.fixture
39def testpoint_checker_factory(testpoint_control):
40 def create_checker(name):
41 def checker(opname):
42 if name not in testpoint_control.enabled_testpoints:
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')
53def 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