Skip to content

Commit e5442a8

Browse files
fix: only set BASIC_MEMORY_ENV=test during pytest runs
The alembic/env.py module was unconditionally setting BASIC_MEMORY_ENV='test' at import time, which caused config.is_test_env to always return True. This prevented the MCP server from starting the file watch service, breaking file sync for external changes. Fix: Only set the env var when PYTEST_CURRENT_TEST is set, indicating an actual pytest run. This preserves test behavior while enabling watch service in production. Fixes #481 Co-authored-by: Paul Hernandez <phernandez@users.noreply.github.com> Signed-off-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
1 parent 6281a81 commit e5442a8

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • src/basic_memory/alembic

src/basic_memory/alembic/env.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
2121

2222
from basic_memory.config import ConfigManager
2323

24-
# set config.env to "test" for pytest to prevent logging to file in utils.setup_logging()
25-
os.environ["BASIC_MEMORY_ENV"] = "test"
24+
# Trigger: only set test env when actually running under pytest
25+
# Why: alembic/env.py is imported during normal operations (MCP server startup, migrations)
26+
# but we only want test behavior during actual test runs
27+
# Outcome: prevents is_test_env from returning True in production, enabling watch service
28+
if os.getenv("PYTEST_CURRENT_TEST") is not None:
29+
os.environ["BASIC_MEMORY_ENV"] = "test"
2630

2731
# Import after setting environment variable # noqa: E402
2832
from basic_memory.models import Base # noqa: E402

0 commit comments

Comments
 (0)