Skip to content

Commit 30259fa

Browse files
committed
fix: skip FastMCP tests when mcp package not installed
CI doesn't install the [mcp] extra, so tests importing from mcp.server.fastmcp fail with ModuleNotFoundError. Add skipif markers to TestFastMCPApp and TestLifespan classes. Also includes ruff format fix for document.py line length.
1 parent 90395fd commit 30259fa

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎docx_editor/document.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ def search_text(self, query: str, context_chars: int = 100) -> list[dict]:
220220
if pos == -1:
221221
break
222222
h = compute_paragraph_hash(p)
223-
before = text[max(0, pos - context_chars):pos]
224-
after = text[pos + len(query):pos + len(query) + context_chars]
223+
before = text[max(0, pos - context_chars) : pos]
224+
after = text[pos + len(query) : pos + len(query) + context_chars]
225225
results.append({
226226
"paragraph_ref": f"P{i + 1}#{h}",
227227
"paragraph_index": i + 1,
@@ -256,7 +256,11 @@ def get_paragraph_text(self, paragraphs: list[str]) -> list[dict]:
256256
p = all_paragraphs[ref.index - 1]
257257
actual_hash = compute_paragraph_hash(p)
258258
if actual_hash != ref.hash:
259-
results.append({"ref": ref_str, "text": None, "error": f"Hash mismatch: expected {ref.hash}, got {actual_hash}"})
259+
results.append({
260+
"ref": ref_str,
261+
"text": None,
262+
"error": f"Hash mismatch: expected {ref.hash}, got {actual_hash}",
263+
})
260264
continue
261265
tm = build_text_map(p)
262266
results.append({"ref": ref_str, "text": tm.text, "error": None})

‎tests/test_mcp/test_server.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
"""Tests for MCP Server following TDD."""
22

33
import asyncio
4+
import importlib.util
45
from unittest.mock import MagicMock
56

7+
import pytest
8+
9+
_has_mcp = bool(importlib.util.find_spec("mcp"))
10+
611

712
class TestMCPServer:
813
"""Test MCP server initialization and lifecycle."""
@@ -120,6 +125,7 @@ def test_shutdown_clears_cache(self):
120125
assert server.cache.size == 0
121126

122127

128+
@pytest.mark.skipif(not _has_mcp, reason="mcp package not installed")
123129
class TestFastMCPApp:
124130
"""Test FastMCP application wiring."""
125131

@@ -177,6 +183,7 @@ def test_main_function_exists(self):
177183
assert callable(main)
178184

179185

186+
@pytest.mark.skipif(not _has_mcp, reason="mcp package not installed")
180187
class TestLifespan:
181188
"""Test server lifespan context manager."""
182189

0 commit comments

Comments
 (0)