fix(ci): clean up test data before AND after each test

Prevents stale data from prior tests/runs from causing false failures
like test_list_devices_empty finding leftover devices.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jason Staack
2026-03-15 06:23:14 -05:00
parent eb60b219b8
commit 93138f0483

View File

@@ -165,6 +165,13 @@ async def admin_session(admin_engine) -> AsyncGenerator[AsyncSession, None]:
Cleanup deletes all rows from test tables after the test.
"""
session = AsyncSession(admin_engine, expire_on_commit=False)
# Clean up any leftover data from previous tests/runs BEFORE yielding
for table in _CLEANUP_TABLES:
try:
await session.execute(text(f"DELETE FROM {table}"))
except Exception:
pass
await session.commit()
try:
yield session
finally: