Skip to content

Commit 0ee7172

Browse files
committed
Fixing tests
1 parent 0d10528 commit 0ee7172

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

sentry_sdk/integrations/asgi.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ async def _sentry_wrapped_send(event):
203203
return await self.app(scope)(
204204
receive, _sentry_wrapped_send
205205
)
206-
207-
# return await callback(transaction)
208-
209206
except Exception as exc:
210207
_capture_exception(
211208
hub, exc, mechanism_type=self.mechanism_type

sentry_sdk/tracing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ def set_context(self, key, value):
665665

666666
def set_http_status(self, http_status):
667667
# type: (int) -> None
668+
super(Transaction, self).set_http_status(http_status)
668669
self.set_context("response", {"status_code": http_status})
669670

670671
def to_json(self):

tests/integrations/asgi/test_asgi.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ async def app(scope, receive, send):
4848

4949
@pytest.fixture
5050
def asgi3_app_with_error():
51+
async def send_with_error(event):
52+
1 / 0
53+
5154
async def app(scope, receive, send):
52-
await send(
55+
await send_with_error(
5356
{
5457
"type": "http.response.start",
5558
"status": 200,
@@ -58,10 +61,7 @@ async def app(scope, receive, send):
5861
],
5962
}
6063
)
61-
62-
1 / 0
63-
64-
await send(
64+
await send_with_error(
6565
{
6666
"type": "http.response.body",
6767
"body": b"Hello, world!",
@@ -167,9 +167,9 @@ async def test_capture_transaction_with_error(
167167
sentry_init(send_default_pii=True, traces_sample_rate=1.0)
168168
app = SentryAsgiMiddleware(asgi3_app_with_error)
169169

170+
events = capture_events()
170171
with pytest.raises(ZeroDivisionError):
171172
async with TestClient(app) as client:
172-
events = capture_events()
173173
await client.get("/")
174174

175175
(error_event, transaction_event) = events
@@ -395,38 +395,35 @@ async def test_auto_session_tracking_with_aggregates(
395395
(
396396
"/message",
397397
"endpoint",
398-
"tests.integrations.asgi.test_asgi.asgi3_app_with_error.<locals>.app",
398+
"tests.integrations.asgi.test_asgi.asgi3_app.<locals>.app",
399399
"component",
400400
),
401401
],
402402
)
403403
@pytest.mark.asyncio
404404
async def test_transaction_style(
405405
sentry_init,
406-
asgi3_app_with_error,
406+
asgi3_app,
407407
capture_events,
408408
url,
409409
transaction_style,
410410
expected_transaction,
411411
expected_source,
412412
):
413413
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)
417415

418416
scope = {
419-
"endpoint": asgi3_app_with_error,
417+
"endpoint": asgi3_app,
420418
"route": url,
421419
"client": ("127.0.0.1", 60457),
422420
}
423421

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)
428425

429-
(_, transaction_event) = events
426+
(transaction_event,) = events
430427

431428
assert transaction_event["transaction"] == expected_transaction
432429
assert transaction_event["transaction_info"] == {"source": expected_source}

0 commit comments

Comments
 (0)