wip(handoff): restore backend suite to green
Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
@@ -5,6 +5,7 @@ Provides test database setup, client fixtures, and authentication helpers.
|
||||
"""
|
||||
|
||||
import os
|
||||
import asyncio
|
||||
from typing import AsyncGenerator
|
||||
import pytest
|
||||
import sqlalchemy as sa
|
||||
@@ -73,6 +74,20 @@ def pytest_collection_modifyitems(config, items):
|
||||
items[:] = selected
|
||||
|
||||
|
||||
@pytest.hookimpl(trylast=True, hookwrapper=True)
|
||||
def pytest_runtest_teardown(item, nextitem):
|
||||
"""Close pytest-asyncio's post-test clean loop before warnings collect it."""
|
||||
yield
|
||||
policy = asyncio.get_event_loop_policy()
|
||||
try:
|
||||
loop = policy.get_event_loop()
|
||||
except RuntimeError:
|
||||
return
|
||||
if not loop.is_running() and not loop.is_closed():
|
||||
loop.close()
|
||||
policy.set_event_loop(None)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def test_db() -> AsyncGenerator[AsyncSession, None]:
|
||||
"""
|
||||
@@ -137,6 +152,7 @@ async def test_db() -> AsyncGenerator[AsyncSession, None]:
|
||||
# Dispose engine first so all pooled connections are released,
|
||||
# then reconnect to perform the schema teardown cleanly.
|
||||
await engine.dispose()
|
||||
await asyncio.sleep(0.01)
|
||||
|
||||
# Drop all tables after test (CASCADE for circular FKs)
|
||||
teardown_engine = create_async_engine(
|
||||
@@ -150,6 +166,7 @@ async def test_db() -> AsyncGenerator[AsyncSession, None]:
|
||||
await conn.execute(sa.text("CREATE SCHEMA public"))
|
||||
finally:
|
||||
await teardown_engine.dispose()
|
||||
await asyncio.sleep(0.01)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
Reference in New Issue
Block a user