Closed lainiwa closed 10 months ago
I did try it, but I'm still having the same error:
@pytest.mark.asyncio()
async def test_ping():
async with AsyncClient(app=app, base_url="http://test") as client:
response = await client.get("/v3/test/ping")
response = await client.get("/v3/test/ping") # <-- works
@pytest.mark.asyncio()
async def test_pong():
async with AsyncClient(app=app, base_url="http://test") as client:
response = await client.get("/v3/test/ping") # <-- fails
response = await client.get("/v3/test/ping")
Upd: it seems i managed to fix it with
@pytest.fixture(scope='session')
def event_loop():
policy = asyncio.get_event_loop_policy()
loop = policy.new_event_loop()
yield loop
loop.close()
I try to follow FastAPI docs on testing, and I'm getting
RuntimeError: Event loop is closed
error when I have ratelimiter enabled.In
main.py
:My
test_ping.py
file:This code fails with
Event loop is closed
on second request, unless the endpoint is not ratelimited.