fix(integration): asyncio auto-mode, per-test truncation, artist images IN-subquery

This commit is contained in:
2026-05-15 22:23:32 -04:00
parent 65a055408b
commit 13be9085b5
3 changed files with 41 additions and 6 deletions
+26
View File
@@ -18,6 +18,8 @@ from sqlalchemy.ext.asyncio import (
)
from sqlalchemy.orm import sessionmaker
from backend.app.models import Base
def _async_database_url() -> str:
user = os.environ.get("DB_USER", "fabledcurator")
@@ -73,3 +75,27 @@ def db_sync(sync_engine):
yield session
finally:
session.rollback()
@pytest.fixture(autouse=True)
def _truncate_after_integration(request):
"""Integration tests exercise app/celery code that commits on its own
connection, which the rollback fixtures above can't undo — so data
would leak between tests. Truncate every model table after each
integration-marked test. Scoped to the integration marker so the
DB-less fast unit job never connects here.
"""
yield
if request.node.get_closest_marker("integration") is None:
return
tables = ", ".join(t.name for t in Base.metadata.sorted_tables)
if not tables:
return
eng = create_engine(_sync_database_url(), future=True)
try:
with eng.begin() as conn:
conn.exec_driver_sql(
f"TRUNCATE {tables} RESTART IDENTITY CASCADE"
)
finally:
eng.dispose()