@@ -382,7 +382,7 @@ def target(
382382
383383
384384@pytest .mark .anyio
385- async def test_async_exception_generators_no_propogation () -> None :
385+ async def test_async_exception_in_teardown () -> None :
386386
387387 errors_found = 0
388388
@@ -400,3 +400,50 @@ def target(_: int = Depends(my_generator)) -> None:
400400 with pytest .raises (ValueError ):
401401 async with DependencyGraph (target = target ).async_ctx () as g :
402402 target (** (await g .resolve_kwargs ()))
403+
404+
405+ @pytest .mark .anyio
406+ async def test_async_propogation_disabled () -> None :
407+
408+ errors_found = 0
409+
410+ async def my_generator () -> AsyncGenerator [int , None ]:
411+ nonlocal errors_found
412+ try :
413+ yield 1
414+ except ValueError :
415+ errors_found += 1
416+ raise Exception ()
417+
418+ def target (_ : int = Depends (my_generator )) -> None :
419+ raise ValueError ()
420+
421+ with pytest .raises (ValueError ):
422+ async with DependencyGraph (target = target ).async_ctx (
423+ exception_propogation = False ,
424+ ) as g :
425+ target (** (await g .resolve_kwargs ()))
426+
427+ assert errors_found == 0
428+
429+
430+ def test_sync_propogation_disabled () -> None :
431+
432+ errors_found = 0
433+
434+ def my_generator () -> Generator [int , None , None ]:
435+ nonlocal errors_found
436+ try :
437+ yield 1
438+ except ValueError :
439+ errors_found += 1
440+ raise Exception ()
441+
442+ def target (_ : int = Depends (my_generator )) -> None :
443+ raise ValueError ()
444+
445+ with pytest .raises (ValueError ):
446+ with DependencyGraph (target = target ).sync_ctx (exception_propogation = False ) as g :
447+ target (** (g .resolve_kwargs ()))
448+
449+ assert errors_found == 0
0 commit comments