@@ -75,9 +75,10 @@ async def handle_unauthorized(self, request: web.Request) -> web.Response:
75
75
76
76
async def handle_exception (self , request : web .Request ) -> web .Response :
77
77
"""
78
- Handle /exception which raises a KeyError
78
+ Handle /exception which raises a CancelledError; this is important, as starting from python 3.8 CancelledError
79
+ extends BaseException instead of Exception
79
80
"""
80
- return {}[ 'key' ]
81
+ raise asyncio . CancelledError ()
81
82
82
83
async def handle_delay (self , request : web .Request ) -> web .Response :
83
84
"""
@@ -213,8 +214,8 @@ async def test_exception(test_client, loop, recorder):
213
214
"""
214
215
client = await test_client (ServerTest .app (loop = loop ))
215
216
216
- resp = await client . get ( '/exception' )
217
- await resp . text () # Need this to trigger Exception
217
+ with pytest . raises ( Exception ):
218
+ await client . get ( '/exception' )
218
219
219
220
segment = recorder .emitter .pop ()
220
221
assert not segment .in_progress
@@ -227,7 +228,7 @@ async def test_exception(test_client, loop, recorder):
227
228
assert request ['url' ] == 'http://127.0.0.1:{port}/exception' .format (port = client .port )
228
229
assert request ['client_ip' ] == '127.0.0.1'
229
230
assert response ['status' ] == 500
230
- assert exception .type == 'KeyError '
231
+ assert exception .type == 'CancelledError '
231
232
232
233
233
234
async def test_unhauthorized (test_client , loop , recorder ):
0 commit comments