From 388bde2ff01bafceffeb9adc9e1aa9aaedeabffc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Feb 2026 17:54:05 +0000 Subject: [PATCH] Fix SQLAlchemy model registration and database session injection in tests - Import all models (DocumentMetadata, FileRecord, ProcessingLog) in conftest.py to register them with SQLAlchemy Base - Override all three get_db functions used across the app (app.database, app.api.common, app.views.base) to ensure tests use the test database - Fixes 21 of 24 failing tests (from "no such table" errors to passing) Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- tests/conftest.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 2b949b50..9060c9de 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -24,6 +24,8 @@ os.environ["SESSION_SECRET"] = "test_secret_key_for_testing_must_be_at_least_32_ from app.database import Base, get_db from app.main import app as fastapi_app +# Import models to register them with SQLAlchemy Base +from app.models import DocumentMetadata, FileRecord, ProcessingLog @pytest.fixture(scope="session") @@ -61,6 +63,10 @@ def db_session(): def client(db_session) -> TestClient: """Create a test client with a fresh database.""" + # Import all the different get_db functions used across the app + from app.api.common import get_db as api_get_db + from app.views.base import get_db as views_get_db + # Override the get_db dependency to use our test database def override_get_db(): try: @@ -68,7 +74,10 @@ def client(db_session) -> TestClient: finally: pass + # Override all variants of get_db fastapi_app.dependency_overrides[get_db] = override_get_db + fastapi_app.dependency_overrides[api_get_db] = override_get_db + fastapi_app.dependency_overrides[views_get_db] = override_get_db # Use base_url to satisfy TrustedHostMiddleware with TestClient(fastapi_app, base_url="http://localhost") as test_client: