Skip to content

Commit 01f3c0a

Browse files
committed
test: cover mcpserver logging utility
1 parent c326aa0 commit 01f3c0a

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import logging
2+
from typing import Any
3+
4+
import pytest
5+
6+
from mcp.server.mcpserver.utilities.logging import configure_logging, get_logger
7+
8+
9+
def test_get_logger_returns_named_logger():
10+
logger = get_logger("mcp.test")
11+
12+
assert logger is logging.getLogger("mcp.test")
13+
14+
15+
def test_configure_logging_uses_rich_handler(monkeypatch: pytest.MonkeyPatch):
16+
calls: list[dict[str, Any]] = []
17+
18+
def fake_basic_config(**kwargs: Any) -> None:
19+
calls.append(kwargs)
20+
21+
monkeypatch.setattr(logging, "basicConfig", fake_basic_config)
22+
23+
configure_logging("WARNING")
24+
25+
handlers = calls[0]["handlers"]
26+
assert calls == [
27+
{
28+
"level": "WARNING",
29+
"format": "%(message)s",
30+
"handlers": handlers,
31+
}
32+
]
33+
assert len(handlers) == 1
34+
assert isinstance(handlers[0], logging.Handler)

0 commit comments

Comments
 (0)