Event loop is closed #2069
Unanswered
vianmixtkz
asked this question in
Potential Issue
Replies: 2 comments 3 replies
-
If you add this to your @pytest.fixture(scope="session", autouse=True)
def event_loop():
"""Reference: https://github.com/pytest-dev/pytest-asyncio/issues/38#issuecomment-264418154"""
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close() Does it solve the issue? |
Beta Was this translation helpful? Give feedback.
2 replies
-
Another interesting observation On this file where I have 3 tests """Module to test the static related endpoints"""
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
def test_get_product(get_headers: dict):
"""Testes the get product static page"""
response = client.get("/static/sitemap/products", headers=get_headers)
assert response.status_code == 200, response.text
def test_get_category(get_headers: dict):
"""Testes the get category static page"""
category = "PU01C01"
response = client.get(f"/static/sitemap/products/{category}", headers=get_headers)
assert response.status_code == 200, response.text
def test_get_brands(get_headers: dict):
"""Testes the get brands static page"""
response = client.get("/static/sitemap/brands", headers=get_headers)
assert response.status_code == 200, response.text The first two works and the third breaks when I launch all of them. Everything works fine on python3.8 and I haven't tried 3.9 and 3.10 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I have recently performed a major upgrade of my app backend and as described below.
This upgrade broke my test suite when using the fastapi/starlette TestClient.
I get RuntimeError: Event loop is closed
I don't understand where this is coming from. My tests are all defined by synchronous function.
I tried to downgrade to fastapi==0.86.0 and starlette==0.20.4 but it didn't solve the problem.
Is it a compatibility issue with python 3.11 ?
Below the callstack of the error:
Beta Was this translation helpful? Give feedback.
All reactions