Skip to content

Commit 53442d7

Browse files
author
Henry Lee
committed
test: cover invalid cli env vars
1 parent 6ab70ea commit 53442d7

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/mcp/cli/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _get_npx_command():
5353
return "npx" # On Unix-like systems, just use npx
5454

5555

56-
def _parse_env_var(env_var: str) -> tuple[str, str]: # pragma: no cover
56+
def _parse_env_var(env_var: str) -> tuple[str, str]:
5757
"""Parse environment variable string in format KEY=VALUE."""
5858
if "=" not in env_var:
5959
logger.error(f"Invalid environment variable format: {env_var}. Must be KEY=VALUE")

tests/cli/test_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ def test_collect_env_vars_from_cli_values():
8686
assert _collect_env_vars(None, ["API_KEY=abc123", "EMPTY="]) == {"API_KEY": "abc123", "EMPTY": ""}
8787

8888

89+
def test_collect_env_vars_exits_on_invalid_cli_value():
90+
"""CLI env vars must use KEY=VALUE format."""
91+
with pytest.raises(SystemExit) as exc_info:
92+
_collect_env_vars(None, ["API_KEY"])
93+
94+
assert exc_info.value.code == 1
95+
96+
8997
def test_collect_env_vars_file_then_cli_override(monkeypatch: pytest.MonkeyPatch, tmp_path: Path):
9098
"""CLI env vars should override values loaded from a .env file."""
9199
env_file = tmp_path / ".env"

0 commit comments

Comments
 (0)