forked from Rockachopa/Timmy-time-dashboard
[loop-cycle-3] fix: isolate unit tests from local .env and real Gitea API (#1206)
This commit is contained in:
@@ -18,6 +18,10 @@ def _make_settings(**env_overrides):
|
||||
"""Create a fresh Settings instance with isolated env vars."""
|
||||
from config import Settings
|
||||
|
||||
# Prevent Pydantic from reading .env file (local .env pollutes defaults)
|
||||
_orig_config = Settings.model_config.copy()
|
||||
Settings.model_config["env_file"] = None
|
||||
|
||||
# Strip keys that might bleed in from the test environment
|
||||
clean_env = {
|
||||
k: v
|
||||
@@ -82,7 +86,10 @@ def _make_settings(**env_overrides):
|
||||
}
|
||||
clean_env.update(env_overrides)
|
||||
with patch.dict(os.environ, clean_env, clear=True):
|
||||
return Settings()
|
||||
try:
|
||||
return Settings()
|
||||
finally:
|
||||
Settings.model_config.update(_orig_config)
|
||||
|
||||
|
||||
# ── normalize_ollama_url ──────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user