@@ -491,9 +491,7 @@ async def make_hat(self, request, ctx) -> NoReturn:
491491 with pytest .raises (ConnectError , match = "We're broken" ):
492492 await client .make_hat (request = Size (inches = 10 ))
493493
494- # Workaround https://github.com/curioswitch/pyqwest/pull/148
495- # TODO: Remove after fix is released
496- assert getattr (transport , "_app_exception" , None ) is None
494+ assert transport .app_exception is None
497495
498496
499497@pytest .mark .asyncio
@@ -515,9 +513,7 @@ def make_similar_hats(
515513 async for _ in client .make_similar_hats (request = Size (inches = 10 )):
516514 pass
517515
518- # Workaround https://github.com/curioswitch/pyqwest/pull/148
519- # TODO: Remove after fix is released
520- assert getattr (transport , "_app_exception" , None ) is None
516+ assert transport .app_exception is None
521517
522518
523519@pytest .mark .asyncio
@@ -536,6 +532,50 @@ async def make_hat(self, request, ctx) -> NoReturn:
536532 with pytest .raises (ConnectError , match = "Internal Server Error" ):
537533 await client .make_hat (request = Size (inches = 10 ))
538534
539- # Workaround https://github.com/curioswitch/pyqwest/pull/148
540- # TODO: Remove after fix is released
541- assert getattr (transport , "_app_exception" , None ) is None
535+ assert transport .app_exception is None
536+
537+
538+ def test_sync_unhandled_exception_logged () -> None :
539+ class RaisingHaberdasher (HaberdasherSync ):
540+ def make_hat (self , request , ctx ) -> NoReturn :
541+ raise TypeError ("Something went wrong" )
542+
543+ app = HaberdasherWSGIApplication (RaisingHaberdasher ())
544+ transport = WSGITransport (app )
545+ http_client = SyncClient (transport )
546+
547+ with (
548+ HaberdasherClientSync (
549+ "http://localhost" , timeout_ms = 200 , http_client = http_client
550+ ) as client ,
551+ pytest .raises (ConnectError , match = "Something went wrong" ),
552+ ):
553+ client .make_hat (request = Size (inches = 10 ))
554+
555+ logged_error = transport .error_stream .getvalue ()
556+ assert "Exception in WSGI application" in logged_error
557+ assert "TypeError: Something went wrong" in logged_error
558+ assert "Traceback" in logged_error
559+
560+
561+ def test_sync_unhandled_exception_logged_stream () -> None :
562+ class RaisingHaberdasher (HaberdasherSync ):
563+ def make_similar_hats (self , request , ctx ) -> NoReturn :
564+ raise TypeError ("Something went wrong" )
565+
566+ app = HaberdasherWSGIApplication (RaisingHaberdasher ())
567+ transport = WSGITransport (app )
568+ http_client = SyncClient (transport )
569+
570+ with (
571+ HaberdasherClientSync (
572+ "http://localhost" , timeout_ms = 200 , http_client = http_client
573+ ) as client ,
574+ pytest .raises (ConnectError , match = "Something went wrong" ),
575+ ):
576+ next (client .make_similar_hats (request = Size (inches = 10 )))
577+
578+ logged_error = transport .error_stream .getvalue ()
579+ assert "Exception in WSGI application" in logged_error
580+ assert "TypeError: Something went wrong" in logged_error
581+ assert "Traceback" in logged_error
0 commit comments