guillaumemaka / fastapi_sample

A Sample FastAPI app
0 stars 0 forks source link

got Future <Future pending cb=[Protocol._on_waiter_completed()]> attached to a different loop #1

Open guillaumemaka opened 10 months ago

guillaumemaka commented 10 months ago

Exception raise when running test:

RuntimeError: Task <Task pending name='Task-25' coro=<test_post_return_201() running at /$HOME/Developer/fastapi_sample/test/test_event.py:50> cb=[_run_until_complete_cb() at /$HOME/.pyenv/versions/3.8.18/lib/python3.8/asyncio/base_events.py:184]> got Future <Future pending cb=[Protocol._on_waiter_completed()]> attached to a different loop
guillaumemaka commented 10 months ago

One solution I found when searching on github for the same issue is:

@pytest.fixture(scope="session", autouse=True)
def event_loop() -> Generator["AbstractEventLoop", Any, None]:
    policy = get_event_loop_policy()
    loop = policy.new_event_loop()
    yield loop
    loop.close()