@@ -703,3 +703,42 @@ async def factorial(n) -> int:
703703 10 ,
704704 )
705705 assert result == ([3628800 ] * 8 )
706+
707+
708+ def test_handling_pending_errors ():
709+ # https://github.com/awolverp/cachebox/issues/57
710+
711+ def key (a , b , c , exception : bool ):
712+ return f"{ a } ,{ b } ,{ c } "
713+
714+ @cachebox .cached (cachebox .TTLCache (1024 , 1 ), key_maker = key )
715+ def calc (a , b , c , exception : bool ):
716+ if exception :
717+ raise ValueError ("first call" )
718+
719+ return a + b + c
720+
721+ with pytest .raises (ValueError ):
722+ calc (1 , 2 , 3 , exception = True )
723+
724+ assert calc (1 , 2 , 3 , exception = False ) == 6
725+
726+
727+ @pytest .mark .asyncio
728+ async def test_async_handling_pending_errors ():
729+ # https://github.com/awolverp/cachebox/issues/57
730+
731+ def key (a , b , c , exception : bool ):
732+ return f"{ a } ,{ b } ,{ c } "
733+
734+ @cachebox .cached (cachebox .TTLCache (1024 , 1 ), key_maker = key )
735+ async def calc (a , b , c , exception : bool ):
736+ if exception :
737+ raise ValueError ("first call" )
738+
739+ return a + b + c
740+
741+ with pytest .raises (ValueError ):
742+ await calc (1 , 2 , 3 , exception = True )
743+
744+ assert await calc (1 , 2 , 3 , exception = False ) == 6
0 commit comments