userver: samples/testsuite-support/tests/test_logcapture.py
Loading...
Searching...
No Matches
samples/testsuite-support/tests/test_logcapture.py
1# /// [select]
2async def test_select(service_client):
3 async with service_client.capture_logs(log_level='INFO') as capture:
4 response = await service_client.get('/logcapture')
5 assert response.status == 200
6
7 records = capture.select(
8 text='Message to capture', link=response.headers['x-yarequestid'],
9 )
10 assert len(records) == 1, capture.select()
11 # /// [select]
12
13
14async def test_subscribe(service_client, mockserver):
15 async with service_client.capture_logs() as capture:
16
17 @capture.subscribe(
18 text='Message to capture', trace_id=mockserver.trace_id,
19 )
20 def log_event(link, **other):
21 pass
22
23 response = await service_client.get(
24 '/logcapture', headers={'x-yatraceid': mockserver.trace_id},
25 )
26 assert response.status == 200
27
28 call = await log_event.wait_call()
29 assert call['link'] == response.headers['x-yarequestid']