File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -1500,7 +1500,8 @@ async def _send_single_request(
15001500 async def on_close (response : Response ) -> None :
15011501 response .elapsed = datetime .timedelta (seconds = await timer .async_elapsed ())
15021502 if hasattr (stream , "aclose" ):
1503- await stream .aclose ()
1503+ with map_exceptions (HTTPCORE_EXC_MAP , request = request ):
1504+ await stream .aclose ()
15041505
15051506 response = Response (
15061507 status_code ,
Original file line number Diff line number Diff line change @@ -303,6 +303,25 @@ async def test_mounted_transport():
303303 assert response .json () == {"app" : "mounted" }
304304
305305
306+ @pytest .mark .usefixtures ("async_environment" )
307+ async def test_response_aclose_map_exceptions ():
308+ class BrokenStream :
309+ async def __aiter__ (self ):
310+ # so we're an AsyncIterator
311+ pass # pragma: nocover
312+
313+ async def aclose (self ):
314+ raise httpcore .CloseError (OSError (104 , "Connection reset by peer" ))
315+
316+ def handle (request : httpx .Request ) -> httpx .Response :
317+ return httpx .Response (200 , stream = BrokenStream ())
318+
319+ async with httpx .AsyncClient (transport = httpx .MockTransport (handle )) as client :
320+ async with client .stream ("GET" , "http://example.com" ) as response :
321+ with pytest .raises (httpx .CloseError ):
322+ await response .aclose ()
323+
324+
306325@pytest .mark .usefixtures ("async_environment" )
307326async def test_async_mock_transport ():
308327 async def hello_world (request ):
You can’t perform that action at this time.
0 commit comments