Skip to content

Commit 232ea33

Browse files
author
Henry Lee
committed
test: avoid optional dotenv dependency
1 parent 58b6687 commit 232ea33

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

tests/cli/test_utils.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import subprocess
22
import sys
33
from pathlib import Path
4+
from types import SimpleNamespace
45
from typing import Any
56

67
import pytest
78

9+
import mcp.cli.cli as cli
810
from mcp.cli.cli import ( # type: ignore[reportPrivateUsage]
911
_build_uv_command,
1012
_collect_env_vars,
@@ -84,10 +86,19 @@ def test_collect_env_vars_from_cli_values():
8486
assert _collect_env_vars(None, ["API_KEY=abc123", "EMPTY="]) == {"API_KEY": "abc123", "EMPTY": ""}
8587

8688

87-
def test_collect_env_vars_file_then_cli_override(tmp_path: Path):
89+
def test_collect_env_vars_file_then_cli_override(monkeypatch: pytest.MonkeyPatch, tmp_path: Path):
8890
"""CLI env vars should override values loaded from a .env file."""
8991
env_file = tmp_path / ".env"
90-
env_file.write_text("API_KEY=file-value\nKEEP=from-file\n", encoding="utf-8")
92+
env_file.write_text("", encoding="utf-8")
93+
94+
def dotenv_values(_: Path) -> dict[str, str]:
95+
return {"API_KEY": "file-value", "KEEP": "from-file"}
96+
97+
monkeypatch.setattr(
98+
cli,
99+
"dotenv",
100+
SimpleNamespace(dotenv_values=dotenv_values),
101+
)
91102

92103
assert _collect_env_vars(env_file, ["API_KEY=cli-value"]) == {"API_KEY": "cli-value", "KEEP": "from-file"}
93104

0 commit comments

Comments
 (0)