Skip to content

Commit 6ab70ea

Browse files
author
Henry Lee
committed
test: fix dev env var ci coverage
1 parent 232ea33 commit 6ab70ea

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,9 +1174,6 @@ uv run mcp dev server.py
11741174
# Add dependencies
11751175
uv run mcp dev server.py --with pandas --with numpy
11761176

1177-
# Load environment variables
1178-
uv run mcp dev server.py --env-var API_KEY=abc123 --env-file .env
1179-
11801177
# Mount local code
11811178
uv run mcp dev server.py --with-editable .
11821179
```

README.v2.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,9 @@ uv run mcp dev server.py
11651165
# Add dependencies
11661166
uv run mcp dev server.py --with pandas --with numpy
11671167

1168+
# Load environment variables
1169+
uv run mcp dev server.py --env-var API_KEY=abc123 --env-file .env
1170+
11681171
# Mount local code
11691172
uv run mcp dev server.py --with-editable .
11701173
```

tests/cli/test_utils.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,38 @@ def dotenv_values(_: Path) -> dict[str, str]:
103103
assert _collect_env_vars(env_file, ["API_KEY=cli-value"]) == {"API_KEY": "cli-value", "KEEP": "from-file"}
104104

105105

106+
def test_collect_env_vars_exits_when_dotenv_missing(monkeypatch: pytest.MonkeyPatch, tmp_path: Path):
107+
"""Should fail clearly when loading a .env file without python-dotenv."""
108+
env_file = tmp_path / ".env"
109+
env_file.write_text("", encoding="utf-8")
110+
monkeypatch.setattr(cli, "dotenv", None)
111+
112+
with pytest.raises(SystemExit) as exc_info:
113+
_collect_env_vars(env_file, [])
114+
115+
assert exc_info.value.code == 1
116+
117+
118+
def test_collect_env_vars_exits_when_dotenv_load_fails(monkeypatch: pytest.MonkeyPatch, tmp_path: Path):
119+
"""Should fail clearly when the .env file cannot be parsed or read."""
120+
env_file = tmp_path / ".env"
121+
env_file.write_text("", encoding="utf-8")
122+
123+
def dotenv_values(_: Path) -> dict[str, str]:
124+
raise ValueError("bad env")
125+
126+
monkeypatch.setattr(
127+
cli,
128+
"dotenv",
129+
SimpleNamespace(dotenv_values=dotenv_values),
130+
)
131+
132+
with pytest.raises(SystemExit) as exc_info:
133+
_collect_env_vars(env_file, [])
134+
135+
assert exc_info.value.code == 1
136+
137+
106138
def test_get_npx_unix_like(monkeypatch: pytest.MonkeyPatch):
107139
"""Should return "npx" on unix-like systems."""
108140
monkeypatch.setattr(sys, "platform", "linux")

0 commit comments

Comments
 (0)