Skip to content

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

Open
paul-nechifor wants to merge 1 commit into
mainfrom
paul/fix/tests-ignore-dotenv
Open

fix(tests): ignore .env under pytest except the LLM API keys#4111
paul-nechifor wants to merge 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   138402     +172     
  Branches    11881    11912      +31     
==========================================
+ Hits       108642   108772     +130     
- Misses      26244    26298      +54     
+ Partials     3344     3332      -12     
Components Coverage Δ
Tests 94.54% <100.00%> (-0.06%) ⬇️
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%) ⬇️

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

Files with missing lines Coverage Δ
dimos/agents/conftest.py 95.83% <ø> (+7.83%) ⬆️
dimos/agents/mcp/conftest.py 95.83% <ø> (+7.83%) ⬆️
...core/coordination/blueprint_config/test_sources.py 100.00% <100.00%> (ø)
dimos/core/global_config.py 92.80% <100.00%> (+4.09%) ⬆️
dimos/core/test_global_config.py 100.00% <100.00%> (ø)
...tal/temporal_memory/test_temporal_memory_module.py 83.72% <ø> (+0.94%) ⬆️
dimos/conftest.py 80.54% <66.66%> (-1.07%) ⬇️
dimos/cli/dimos.py 97.89% <33.33%> (-2.11%) ⬇️
...imos/core/coordination/blueprint_config/sources.py 86.44% <50.00%> (+4.54%) ⬆️

... 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..."

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant