11import asyncio
22import importlib
3+ import os
34import shutil
45from datetime import timedelta
56from pathlib import Path
1920
2021@pytest .fixture (scope = "session" , autouse = True )
2122def generate_rpc_client () -> None :
22- shutil .rmtree ("tests/codegen/rpc/generated" )
23+ shutil .rmtree ("tests/codegen/rpc/generated" , ignore_errors = True )
24+ os .makedirs ("tests/codegen/rpc/generated" )
2325
2426 def file_opener (path : Path ) -> TextIO :
2527 return open (path , "w" )
@@ -34,12 +36,14 @@ def file_opener(path: Path) -> TextIO:
3436 method_filter = None ,
3537 )
3638
39+ @pytest .fixture (scope = "session" , autouse = True )
40+ def reload_rpc_import (generate_rpc_client : None ) -> None :
41+ import tests .codegen .rpc .generated
42+ importlib .reload (tests .codegen .rpc .generated )
3743
3844@pytest .mark .asyncio
3945@pytest .mark .parametrize ("handlers" , [{** basic_rpc_method }])
4046async def test_basic_rpc (client : Client ) -> None :
41- import tests .codegen .rpc .generated
42- importlib .reload (tests .codegen .rpc .generated )
4347 from tests .codegen .rpc .generated import RpcClient
4448
4549 res = await RpcClient (client ).test_service .rpc_method (
@@ -69,8 +73,6 @@ async def rpc_timeout_handler(request: str, context: grpc.aio.ServicerContext) -
6973@pytest .mark .asyncio
7074@pytest .mark .parametrize ("handlers" , [{** rpc_timeout_method }])
7175async def test_rpc_timeout (client : Client ) -> None :
72- import tests .codegen .rpc .generated
73- importlib .reload (tests .codegen .rpc .generated )
7476 from tests .codegen .rpc .generated import RpcClient
7577
7678 with pytest .raises (RiverException ):
0 commit comments