Skip to content

Commit

Permalink
Add tests for chained exceptions in Starlette
Browse files Browse the repository at this point in the history
This required bumping the Starlette version because of this issue:
encode/starlette#1114
  • Loading branch information
imjoehaines committed Feb 15, 2022
1 parent c93d12f commit 7d636f8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions tests/integrations/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from bugsnag.breadcrumbs import BreadcrumbType
from tests.utils import IntegrationTest, ScaryException

import pytest


class TestASGIMiddleware(IntegrationTest):
def setUp(self):
Expand Down Expand Up @@ -287,3 +289,41 @@ async def index(req):
'from': 'http://testserver/abc/xyz'
}
assert breadcrumbs[0]['type'] == BreadcrumbType.NAVIGATION.value

def test_chained_exceptions(self):
app = Starlette()

async def other_func():
raise ScaryException('fell winds!')

@app.route('/')
async def index(req):
try:
await other_func()
except ScaryException as scary:
raise Exception('disconcerting breeze.') from scary

app = TestClient(BugsnagMiddleware(app))

with pytest.raises(Exception):
app.get('/')

assert self.sent_report_count == 1

payload = self.server.received[0]['json_body']

print(payload)
assert len(payload['events'][0]['exceptions']) == 2

exception1 = payload['events'][0]['exceptions'][0]
exception2 = payload['events'][0]['exceptions'][1]

assert 'Exception' == exception1['errorClass']
assert 'disconcerting breeze.' == exception1['message']
assert 'index' == exception1['stacktrace'][0]['method']

assert 'tests.utils.ScaryException' == exception2['errorClass']
assert 'fell winds!' == exception2['message']
assert len(exception2['stacktrace']) == 2
assert 'other_func' == exception2['stacktrace'][0]['method']
assert 'index' == exception2['stacktrace'][1]['method']
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ deps=
pytest-cov
requests: requests
wsgi: webtest==2.0.35
asgi: starlette==0.13.6
asgi: starlette==0.18.0
asgi: requests
bottle: webtest==2.0.35
bottle: bottle==0.12.18
Expand Down

0 comments on commit 7d636f8

Please sign in to comment.