In my fastapi application i have written test cases using pytest. My tests folder includes
conftest.py
import pytest
from fastapi.testclient import TestClient
from main import app
@pytest.fixture(scope="session")
def test_client():
client = TestClient(app)
yield client
test_cases.py
def test_get_courses(test_client):
response = test_client.get("/courses/")
assert response.status_code == 200
def test_get_course_overview(test_client):
course_id = "66c21d35c014f6ce1d0c29ab"
response = test_client.get(f"/courses/{course_id}")
print(response.json())
assert response.status_code == 200
When i run single test cases no issue but if i run all test cases it give below error for printing response.json
{'status': False, 'status_code': 500, 'detail': 'Event loop is closed'}
I have use session based scope and also tried with pytest-asyncio still the same.
Thanks for solutions.