feat: centralized environment handling, ensures ZEN_MCP_FORCE_ENV_OVERRIDE is honored correctly
fix: updated tests to override env variables they need instead of relying on the current values from .env
This commit is contained in:
@@ -15,6 +15,11 @@ parent_dir = Path(__file__).resolve().parent.parent
|
||||
if str(parent_dir) not in sys.path:
|
||||
sys.path.insert(0, str(parent_dir))
|
||||
|
||||
import utils.env as env_config # noqa: E402
|
||||
|
||||
# Ensure tests operate with runtime environment rather than .env overrides during imports
|
||||
env_config.reload_env({"ZEN_MCP_FORCE_ENV_OVERRIDE": "false"})
|
||||
|
||||
# Set default model to a specific value for tests to avoid auto mode
|
||||
# This prevents all tests from failing due to missing model parameter
|
||||
os.environ["DEFAULT_MODEL"] = "gemini-2.5-flash"
|
||||
@@ -176,3 +181,26 @@ def clear_model_restriction_env(monkeypatch):
|
||||
|
||||
for var in restriction_vars:
|
||||
monkeypatch.delenv(var, raising=False)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def disable_force_env_override(monkeypatch):
|
||||
"""Default tests to runtime environment visibility unless they explicitly opt in."""
|
||||
|
||||
monkeypatch.setenv("ZEN_MCP_FORCE_ENV_OVERRIDE", "false")
|
||||
env_config.reload_env({"ZEN_MCP_FORCE_ENV_OVERRIDE": "false"})
|
||||
monkeypatch.setenv("DEFAULT_MODEL", "gemini-2.5-flash")
|
||||
monkeypatch.setenv("MAX_CONVERSATION_TURNS", "50")
|
||||
|
||||
import importlib
|
||||
|
||||
import config
|
||||
import utils.conversation_memory as conversation_memory
|
||||
|
||||
importlib.reload(config)
|
||||
importlib.reload(conversation_memory)
|
||||
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
env_config.reload_env()
|
||||
|
||||
Reference in New Issue
Block a user