@@ -48,8 +48,11 @@ async def app(scope, receive, send):
48
48
49
49
@pytest .fixture
50
50
def asgi3_app_with_error ():
51
+ async def send_with_error (event ):
52
+ 1 / 0
53
+
51
54
async def app (scope , receive , send ):
52
- await send (
55
+ await send_with_error (
53
56
{
54
57
"type" : "http.response.start" ,
55
58
"status" : 200 ,
@@ -58,10 +61,7 @@ async def app(scope, receive, send):
58
61
],
59
62
}
60
63
)
61
-
62
- 1 / 0
63
-
64
- await send (
64
+ await send_with_error (
65
65
{
66
66
"type" : "http.response.body" ,
67
67
"body" : b"Hello, world!" ,
@@ -167,9 +167,9 @@ async def test_capture_transaction_with_error(
167
167
sentry_init (send_default_pii = True , traces_sample_rate = 1.0 )
168
168
app = SentryAsgiMiddleware (asgi3_app_with_error )
169
169
170
+ events = capture_events ()
170
171
with pytest .raises (ZeroDivisionError ):
171
172
async with TestClient (app ) as client :
172
- events = capture_events ()
173
173
await client .get ("/" )
174
174
175
175
(error_event , transaction_event ) = events
@@ -395,38 +395,35 @@ async def test_auto_session_tracking_with_aggregates(
395
395
(
396
396
"/message" ,
397
397
"endpoint" ,
398
- "tests.integrations.asgi.test_asgi.asgi3_app_with_error .<locals>.app" ,
398
+ "tests.integrations.asgi.test_asgi.asgi3_app .<locals>.app" ,
399
399
"component" ,
400
400
),
401
401
],
402
402
)
403
403
@pytest .mark .asyncio
404
404
async def test_transaction_style (
405
405
sentry_init ,
406
- asgi3_app_with_error ,
406
+ asgi3_app ,
407
407
capture_events ,
408
408
url ,
409
409
transaction_style ,
410
410
expected_transaction ,
411
411
expected_source ,
412
412
):
413
413
sentry_init (send_default_pii = True , traces_sample_rate = 1.0 )
414
- app = SentryAsgiMiddleware (
415
- asgi3_app_with_error , transaction_style = transaction_style
416
- )
414
+ app = SentryAsgiMiddleware (asgi3_app , transaction_style = transaction_style )
417
415
418
416
scope = {
419
- "endpoint" : asgi3_app_with_error ,
417
+ "endpoint" : asgi3_app ,
420
418
"route" : url ,
421
419
"client" : ("127.0.0.1" , 60457 ),
422
420
}
423
421
424
- with pytest .raises (ZeroDivisionError ):
425
- async with TestClient (app , scope = scope ) as client :
426
- events = capture_events ()
427
- await client .get (url )
422
+ async with TestClient (app , scope = scope ) as client :
423
+ events = capture_events ()
424
+ await client .get (url )
428
425
429
- (_ , transaction_event ) = events
426
+ (transaction_event , ) = events
430
427
431
428
assert transaction_event ["transaction" ] == expected_transaction
432
429
assert transaction_event ["transaction_info" ] == {"source" : expected_source }
0 commit comments