You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Test DB setup should follow standard Python load_dotenv convention #585
Tests connect to the dev database (ocotilloapi_dev) instead of the test database (ocotilloapi_test) because multiple load_dotenv(override=True) calls stomp env vars set by the test framework. There are 7 load_dotenv calls across the codebase with inconsistent override behavior:
File
Call
Override
tests/__init__.py:23
load_dotenv(override=True)
Yes
tests/conftest.py:7
load_dotenv(override=True)
Yes
db/engine.py:35
load_dotenv(override=False)
No
alembic/env.py:47
load_dotenv()
No (default)
main.py:7
load_dotenv()
No (default)
cli/cli.py:28
load_dotenv(override=True)
Yes
transfers/transfer.py:39
load_dotenv(override=False)
No
The override=True calls re-read .env (which has POSTGRES_DB=ocotilloapi_dev) and overwrite the test framework's POSTGRES_DB=ocotilloapi_test.
Proposed fix: follow standard Python convention
The standard convention in the Python/FastAPI ecosystem:
load_dotenv() (no override) everywhere — .env provides defaults, not overrides. Env vars already set by the runtime, test framework, or CI take precedence. This is the default behavior of python-dotenv for a reason.
Set test env vars beforeload_dotenv() — in tests/__init__.py, set POSTGRES_DB=ocotilloapi_test before calling load_dotenv(). Since the default is no-override, .env's value won't stomp it.
One load_dotenv() per entry point — main.py, cli/cli.py, tests/__init__.py, transfers/transfer.py each call it once. Library code (db/engine.py) and Alembic (env.py) should NOT call load_dotenv() — they rely on the entry point having loaded it.
Concrete changes
tests/__init__.py: set POSTGRES_DB=ocotilloapi_testbeforeload_dotenv(), remove override=True
Activity
github-actions commentedon Mar 4, 2026
Linked Jira ticket created: BDMS-630