19async def service_client(
20 service_daemon_instance,
22 service_client_options,
23 userver_service_client_options,
24 userver_client_cleanup,
25 _testsuite_client_config: client.TestsuiteClientConfig,
28 Main fixture that provides access to userver based service.
30 @snippet samples/testsuite-support/tests/test_ping.py service_client
31 @anchor service_client
32 @ingroup userver_testsuite_fixtures
34 if not _testsuite_client_config.testsuite_action_path:
35 yield _ClientDiagnose(service_baseurl, **service_client_options)
38 aiohttp_client = client.AiohttpClient(
40 **userver_service_client_options,
50 service_logs_update_position,
51 servicelogs_register_flusher,
52 _dynamic_config_defaults_storage,
55) -> typing.Callable[[client.Client], typing.AsyncGenerator]:
57 Contains the pre-test and post-test setup that depends
58 on @ref service_client.
60 Feel free to override, but in that case make sure to call the original
61 `userver_client_cleanup` fixture instance.
63 @ingroup userver_testsuite_fixtures
65 marker = request.node.get_closest_marker(
'suspend_periodic_tasks')
67 tasks_to_suspend = marker.args
71 @compat.asynccontextmanager
72 async def cleanup_manager(client: client.Client):
73 @servicelogs_register_flusher
76 await client.log_flush()
77 except aiohttp.client_exceptions.ClientError:
84 service_logs_update_position()
86 await _dynamic_config_defaults_storage.update(client, dynamic_config)
89 await client.suspend_periodic_tasks(tasks_to_suspend)
93 await client.resume_all_periodic_tasks()
95 return cleanup_manager
129 userver_monitor_client_options,
131) -> client.ClientMonitor:
133 Main fixture that provides access to userver monitor listener.
135 @snippet samples/testsuite-support/tests/test_metrics.py metrics labels
136 @ingroup userver_testsuite_fixtures
138 aiohttp_client = client.AiohttpClientMonitor(
140 **userver_monitor_client_options,
148class _ClientDiagnose(base_service_client.Client):
149 def __getattr__(self, name: str) ->
None:
150 raise AttributeError(
151 f
'"Client" object has no attribute "{name}". '
152 'Note that "service_client" fixture returned the basic '
153 '"testsuite.daemons.service_client.Client" client rather than '
154 'a "pytest_userver.client.Client" client with userver '
155 'extensions. That happened because the service '
156 'static configuration file contains no "tests-control" '
157 'component with "action" field.',
162@pytest.fixture(name='service_client_options')
163def _service_client_options(
164 service_client_options,
165 service_client_default_headers,
171 service_client_options,
173 **service_client_default_headers,
174 mockserver.trace_id_header: mockserver.trace_id,
180def userver_service_client_options(
181 service_client_options,
182 _testsuite_client_config: client.TestsuiteClientConfig,
185 service_periodic_tasks_state,
188 cache_invalidation_state,
189 userver_cache_control,
191 userver_allow_all_caches_invalidation,
194 **service_client_options,
195 config=_testsuite_client_config,
197 testpoint_control=testpoint_control,
198 periodic_tasks_state=service_periodic_tasks_state,
199 log_capture_fixture=userver_log_capture,
200 mocked_time=mocked_time,
201 cache_invalidation_state=cache_invalidation_state,
202 cache_control=userver_cache_control,
203 asyncexc_check=asyncexc_check,
204 allow_all_caches_invalidation=userver_allow_all_caches_invalidation,
209def userver_monitor_client_options(
210 service_client_options,
211 _testsuite_client_config: client.TestsuiteClientConfig,
213 return dict(**service_client_options, config=_testsuite_client_config)
219@pytest.fixture(scope='session')