Created
July 1, 2023 20:58
-
-
Save TomFaulkner/ee1859ad041fd857964bc3ec2c342c9b to your computer and use it in GitHub Desktop.
Fix FastAPI + some async db + httpx tests having no event loop / different event loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Fixes the following error: | |
RuntimeError: Task <Task pending name='Task-215' coro=<test_view() running at | |
{proj}/{test_dir}/test_view.py:23> cb=[_run_until_complete_cb() at /{env_dir}/python3.11/asyncio/base_events.py:180] | |
> got Future <Future pending> attached to a different loop | |
""" | |
import asyncio | |
from typing import Generator | |
import pytest | |
@pytest.fixture(scope="session") | |
def event_loop() -> Generator: | |
loop = asyncio.get_event_loop_policy().new_event_loop() | |
yield loop | |
loop.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment