fix: isolate tests on in-memory SQLite to protect production database

Tests were importing the production engine and dropping all tables on
teardown, corrupting topology.db in the Docker volume. Set DATABASE_URL
to sqlite:///:memory: before any import in the test file, and use
StaticPool in database.py when running against :memory: so all
connections share the same in-memory database.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-18 18:22:32 +02:00
parent e8ca10f1b7
commit a0b5a55daf
2 changed files with 9 additions and 4 deletions
+3
View File
@@ -15,6 +15,9 @@ from sqlalchemy import text
import sys, os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Redirect to an in-memory database so tests never touch the production volume.
os.environ["DATABASE_URL"] = "sqlite:///:memory:"
from database import engine, Base
from main import app, _migrate_users_must_change_password, _migrate_users_token_version, _migrate_users