Skip to content

Commit

Permalink
test: add 'event_loop' fixture
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Jeny Sadadia committed Aug 15, 2022
1 parent 1d23e72 commit fcf0146
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""pytest fixtures for KernelCI API"""

from unittest.mock import AsyncMock
import asyncio
import fakeredis.aioredis
from fastapi.testclient import TestClient
import pytest
Expand All @@ -35,6 +36,15 @@ def client():
return TestClient(app)


@pytest.fixture
def event_loop():
"""Create an instance of the default event loop for each test case"""
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
yield loop
loop.close()


@pytest.fixture
def mock_db_create(mocker):
"""Mocks async call to Database class method used to create object"""
Expand Down

0 comments on commit fcf0146

Please sign in to comment.