Skip to content

Commit a3f5eec

Browse files
committed
test(mcp): cover main() on a successful start, quiet and verbose
1 parent 2b66474 commit a3f5eec

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎tests/test_mcp_server.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,34 @@ def test_build_server_writes_the_report_into_the_given_buffer(monkeypatch, capsy
182182
assert capsys.readouterr().err == ""
183183

184184

185+
def _serve_without_blocking(monkeypatch) -> None:
186+
"""Let main() return: no stdio loop, and no atexit handler left behind."""
187+
monkeypatch.setattr(server.MCPServer, "run", lambda self, **kwargs: None)
188+
monkeypatch.setattr(server.atexit, "register", lambda func: func)
189+
190+
191+
def test_main_is_quiet_on_a_successful_start(monkeypatch, capsys):
192+
_configure(monkeypatch)
193+
_serve_without_blocking(monkeypatch)
194+
195+
server.main()
196+
197+
assert "[osw]" not in capsys.readouterr().err
198+
199+
200+
def test_main_prints_the_report_when_osw_verbose_is_set(monkeypatch, capsys):
201+
_configure(monkeypatch)
202+
monkeypatch.setenv("OSW_VERBOSE", "true")
203+
config.reset()
204+
_serve_without_blocking(monkeypatch)
205+
206+
server.main()
207+
208+
err = capsys.readouterr().err
209+
assert "[osw] credentials" in err
210+
assert "[osw] env file" in err
211+
212+
185213
def test_main_prints_the_report_when_startup_fails(monkeypatch, tmp_path, capsys):
186214
# No OSW_DOMAIN: _build_server raises, and that is exactly when the
187215
# configuration sources have to be visible, OSW_VERBOSE or not.

0 commit comments

Comments
 (0)