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:
parent
25494ca098
commit
bd4bf53084
@ -25,15 +25,19 @@ from gns3server.app import app
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
if sys.platform.startswith("win"):
|
||||
@pytest.yield_fixture(scope="session")
|
||||
def loop(request):
|
||||
"""Return an event loop and destroy it at the end of test"""
|
||||
def event_loop(request):
|
||||
"""
|
||||
Overwrite pytest_asyncio event loop.
|
||||
"""
|
||||
|
||||
loop = asyncio.ProactorEventLoop()
|
||||
asyncio.set_event_loop(loop) # Replace main loop to avoid conflict between tests
|
||||
# As of Python 3.8, the default event loop on Windows is Proactor
|
||||
if sys.platform.startswith("win") and sys.version_info < (3, 8):
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
|
||||
loop = asyncio.get_event_loop_policy().new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
yield loop
|
||||
asyncio.set_event_loop(None)
|
||||
loop.close()
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
|
Loading…
Reference in New Issue
Block a user