Skip to content

Commit cd96e0d

Browse files
author
Jeny Sadadia
committed
test: add 'event_loop' fixture
Default event loop is being closed after running `async` tests from test_pubsub.py. This fails subscribe and unsubscribe handler tests. Need to create an instance for default event loop for all the async tests. Signed-off-by: Jeny Sadadia <[email protected]>
1 parent 09847f9 commit cd96e0d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/conftest.py

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""pytest fixtures for KernelCI API"""
1212

1313
from unittest.mock import AsyncMock
14+
import asyncio
1415
import fakeredis.aioredis
1516
from fastapi.testclient import TestClient
1617
import pytest
@@ -35,6 +36,15 @@ def client():
3536
return TestClient(app)
3637

3738

39+
@pytest.fixture
40+
def event_loop():
41+
"""Create an instance of the default event loop for each test case"""
42+
loop = asyncio.new_event_loop()
43+
asyncio.set_event_loop(loop)
44+
yield loop
45+
loop.close()
46+
47+
3848
@pytest.fixture
3949
def mock_db_create(mocker):
4050
"""Mocks async call to Database class method used to create object"""

0 commit comments

Comments
 (0)