1
0
mirror of https://github.com/GNS3/gns3-server synced 2025-01-13 17:40:54 +00:00

Use ProactorEventLoop with pytest-asyncio

This commit is contained in:
grossmj 2020-10-20 00:46:46 +10:30
parent 25494ca098
commit bd4bf53084

View File

@ -25,15 +25,19 @@ from gns3server.app import app
from httpx import AsyncClient from httpx import AsyncClient
if sys.platform.startswith("win"): @pytest.yield_fixture(scope="session")
@pytest.yield_fixture(scope="session") def event_loop(request):
def loop(request): """
"""Return an event loop and destroy it at the end of test""" Overwrite pytest_asyncio event loop.
"""
loop = asyncio.ProactorEventLoop() # As of Python 3.8, the default event loop on Windows is Proactor
asyncio.set_event_loop(loop) # Replace main loop to avoid conflict between tests if sys.platform.startswith("win") and sys.version_info < (3, 8):
yield loop asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
asyncio.set_event_loop(None) loop = asyncio.get_event_loop_policy().new_event_loop()
asyncio.set_event_loop(loop)
yield loop
loop.close()
@pytest.fixture(scope='function') @pytest.fixture(scope='function')