Skip to content

Commit 6c7d79a

Browse files
committed
Stop reading main()'s return value in CLI tests
main() returns None (Sonar S3516 fix from the previous round), so ``rc = main(argv)`` followed by ``assert rc is None`` trips Sonar S3699 ("Remove this use of the output from 'main'; 'main' doesn't return anything"). Drop the binding entirely and call main() purely for its side effect.
1 parent ba95f89 commit 6c7d79a

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

test/unit_test/headless/test_mcp_cli.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,31 @@
77

88

99
def _capture(monkeypatch, argv):
10+
"""Run ``main(argv)`` for its side effect and return captured stdout."""
1011
buffer = io.StringIO()
1112
monkeypatch.setattr(sys, "stdout", buffer)
12-
rc = main(argv)
13-
return rc, buffer.getvalue()
13+
main(argv)
14+
return buffer.getvalue()
1415

1516

1617
def test_list_tools_emits_json_and_exits(monkeypatch):
17-
rc, output = _capture(monkeypatch, ["--list-tools"])
18-
assert rc is None
18+
output = _capture(monkeypatch, ["--list-tools"])
1919
descriptors = json.loads(output)
2020
assert isinstance(descriptors, list)
2121
assert descriptors
2222
assert all("name" in d and "inputSchema" in d for d in descriptors)
2323

2424

2525
def test_list_tools_with_read_only_drops_destructive(monkeypatch):
26-
_, output = _capture(monkeypatch, ["--list-tools", "--read-only"])
26+
output = _capture(monkeypatch, ["--list-tools", "--read-only"])
2727
descriptors = json.loads(output)
2828
names = {d["name"] for d in descriptors}
2929
assert "ac_click_mouse" not in names
3030
assert "ac_get_mouse_position" in names
3131

3232

3333
def test_list_resources_emits_json(monkeypatch):
34-
rc, output = _capture(monkeypatch, ["--list-resources"])
35-
assert rc is None
34+
output = _capture(monkeypatch, ["--list-resources"])
3635
descriptors = json.loads(output)
3736
assert isinstance(descriptors, list)
3837
uris = {d["uri"] for d in descriptors}
@@ -41,8 +40,7 @@ def test_list_resources_emits_json(monkeypatch):
4140

4241

4342
def test_list_prompts_emits_json(monkeypatch):
44-
rc, output = _capture(monkeypatch, ["--list-prompts"])
45-
assert rc is None
43+
output = _capture(monkeypatch, ["--list-prompts"])
4644
descriptors = json.loads(output)
4745
assert isinstance(descriptors, list)
4846
names = {d["name"] for d in descriptors}
@@ -55,6 +53,5 @@ def test_no_flags_starts_stdio_server(monkeypatch):
5553
import je_auto_control.utils.mcp_server.__main__ as cli_mod
5654
monkeypatch.setattr(cli_mod, "start_mcp_stdio_server",
5755
lambda: started.append(True))
58-
rc = main([])
59-
assert rc is None
56+
main([])
6057
assert started == [True]

0 commit comments

Comments
 (0)