diff --git a/surfsense_backend/tests/conftest.py b/surfsense_backend/tests/conftest.py index 19349affb..e1f0bc178 100644 --- a/surfsense_backend/tests/conftest.py +++ b/surfsense_backend/tests/conftest.py @@ -4,10 +4,14 @@ from __future__ import annotations import os -os.environ.setdefault( - "DATABASE_URL", - "postgresql+asyncpg://postgres:postgres@localhost:5432/surfsense_test", +_DEFAULT_TEST_DB = ( + "postgresql+asyncpg://postgres:postgres@localhost:5432/surfsense_test" ) +TEST_DATABASE_URL = os.environ.get("TEST_DATABASE_URL", _DEFAULT_TEST_DB) + +# Force the app to use the test database regardless of any pre-existing +# DATABASE_URL in the environment (e.g. from .env or shell profile). +os.environ["DATABASE_URL"] = TEST_DATABASE_URL import pytest diff --git a/surfsense_backend/tests/integration/conftest.py b/surfsense_backend/tests/integration/conftest.py index 9dff257df..8b92a5aa8 100644 --- a/surfsense_backend/tests/integration/conftest.py +++ b/surfsense_backend/tests/integration/conftest.py @@ -1,4 +1,3 @@ -import os import uuid from unittest.mock import AsyncMock, MagicMock @@ -18,14 +17,10 @@ from app.db import ( User, ) from app.indexing_pipeline.connector_document import ConnectorDocument +from tests.conftest import TEST_DATABASE_URL _EMBEDDING_DIM = app_config.embedding_model_instance.dimension -_DEFAULT_TEST_DB = ( - "postgresql+asyncpg://postgres:postgres@localhost:5432/surfsense_test" -) -TEST_DATABASE_URL = os.environ.get("TEST_DATABASE_URL", _DEFAULT_TEST_DB) - @pytest_asyncio.fixture(scope="session") async def async_engine():