Skip to content

fix(tests): ignore .env under pytest except the LLM API keys - #4111

Merged
mustafab0 merged 1 commit into
mainfrom
paul/fix/tests-ignore-dotenv
Sep 13, 2026
Merged

fix(tests): ignore .env under pytest except the LLM API keys#4111
mustafab0 merged 1 commit into
mainfrom
paul/fix/tests-ignore-dotenv

Conversation

@paul-nechifor

Copy link
Copy Markdown
Contributor

Problem

ROBOT_IP in .env (and others) leaked into tests.

Solution

Ignore .env when running tests (but do add OPENAI_API_KEY and a few others we use).

A developer's .env (ROBOT_IP, SIMULATION, ...) leaked into tests through
two doors: GlobalConfig's env_file, and the conftest load_dotenv() that
exported the whole file into os.environ, which every GlobalConfig() and
every forkserver worker then read.

ENV_FILE in global_config is now the single switch: None when pytest's
PYTEST_VERSION is in the environment (set before conftests load and
inherited by every child process), ".env" otherwise. GlobalConfig, the
CLI's load_dotenv() and blueprint_config.sources all follow it. The root
conftest exports only OPENAI_API_KEY, ANTHROPIC_API_KEY and
ALIBABA_API_KEY from .env, skipping empty values and never overriding a
shell variable; the redundant load_dotenv() calls in nested conftests
are gone.
@codecov

codecov Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.68421% with 5 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
dimos/cli/dimos.py 33.33% 1 Missing and 1 partial ⚠️
...imos/core/coordination/blueprint_config/sources.py 50.00% 1 Missing and 1 partial ⚠️
dimos/conftest.py 66.66% 0 Missing and 1 partial ⚠️
@@            Coverage Diff             @@
##             main    #4111      +/-   ##
==========================================
- Coverage   78.59%   78.59%   -0.01%     
==========================================
  Files        1460     1460              
  Lines      138230   138244      +14     
  Branches    11881    11900      +19     
==========================================
+ Hits       108642   108652      +10     
+ Misses      26244    26243       -1     
- Partials     3344     3349       +5     
Components Coverage Δ
Tests 94.59% <100.00%> (-0.01%) ⬇️
Flag Coverage Δ
OS-ubuntu-24.04-arm 74.77% <73.68%> (-0.01%) ⬇️
OS-ubuntu-latest 75.48% <73.68%> (+<0.01%) ⬆️
Py-3.10 75.25% <73.68%> (+<0.01%) ⬆️
Py-3.11 75.46% <73.68%> (-0.01%) ⬇️
Py-3.12 75.46% <73.68%> (-0.01%) ⬇️
SelfHosted-Large 30.77% <36.84%> (-0.01%) ⬇️
SelfHosted-Linux 35.68% <36.84%> (-0.02%) ⬇️
SelfHosted-macOS 35.01% <36.84%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
dimos/agents/conftest.py 87.50% <ø> (-0.50%) ⬇️
dimos/agents/mcp/conftest.py 87.50% <ø> (-0.50%) ⬇️
...core/coordination/blueprint_config/test_sources.py 100.00% <100.00%> (ø)
dimos/core/global_config.py 88.80% <100.00%> (+0.09%) ⬆️
dimos/core/test_global_config.py 100.00% <100.00%> (ø)
...tal/temporal_memory/test_temporal_memory_module.py 82.68% <ø> (-0.09%) ⬇️
dimos/conftest.py 81.00% <66.66%> (-0.61%) ⬇️
dimos/cli/dimos.py 97.89% <33.33%> (-2.11%) ⬇️
...imos/core/coordination/blueprint_config/sources.py 80.50% <50.00%> (-1.39%) ⬇️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@greptile-apps

greptile-apps Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

Safe to merge: the tested pytest configuration flows isolate unrelated .env values and retain the intended LLM credential behavior.

What we checked:

  • They executed a focused pytest session against the targeted modules (dimos/conftest.py, dimos/core/global_config.py, and dimos/core/coordination/blueprint_config/sources.py) using a temporary working-directory .env to exercise the code paths. T-Rex
  • They compared the parent revision with the updated change and observed that the parent loaded ROBOT_IP into GlobalConfig while the updated code ignored it and did not load blueprint module environment values, and they confirmed that OPENAI_API_KEY retained precedence, a non-empty dotenv ANTHROPIC_API_KEY was available, and the focused configuration suite completed with 10 tests passing. T-Rex
  • They verified that no source files were modified and that only ignored proof artifacts were authored, following the same in-process test flow used for the before/after comparisons. T-Rex

Summary

  • This change prevents general developer .env values from influencing pytest configuration while preserving supported LLM API-key loading and shell-variable precedence. The exercised configuration paths behaved as intended.

Reviews (1) · Last reviewed commit: "fix(tests): ignore .env under pytest exc..."

@github-actions github-actions Bot added the ready-to-merge Required CI checks have passed on this PR label Sep 13, 2026
@mustafab0
mustafab0 added this pull request to the merge queue Sep 13, 2026
Merged via the queue into main with commit f01a8ee Sep 13, 2026
62 of 75 checks passed
@mustafab0
mustafab0 deleted the paul/fix/tests-ignore-dotenv branch September 13, 2026 07:48
@github-actions

Copy link
Copy Markdown
Contributor

Successfully created backport PR for release/0.0.14:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport release/0.0.14 ready-to-merge Required CI checks have passed on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants