55# pyright: reportUnknownArgumentType=false
66# pyright: reportUnknownMemberType=false
77
8- import sys
98from pathlib import Path
109
1110import pytest
@@ -65,12 +64,17 @@ async def test_direct_call_tool_result_return():
6564
6665
6766@pytest .mark .anyio
68- async def test_desktop (monkeypatch : pytest .MonkeyPatch ):
67+ async def test_desktop (tmp_path : Path , monkeypatch : pytest .MonkeyPatch ):
6968 """Test the desktop server"""
70- # Mock desktop directory listing
71- mock_files = [Path ("/fake/path/file1.txt" ), Path ("/fake/path/file2.txt" )]
72- monkeypatch .setattr (Path , "iterdir" , lambda self : mock_files ) # type: ignore[reportUnknownArgumentType]
73- monkeypatch .setattr (Path , "home" , lambda : Path ("/fake/home" ))
69+ # Build a real Desktop directory under tmp_path rather than patching
70+ # Path.iterdir — a class-level patch breaks jsonschema_specifications'
71+ # import-time schema discovery when this test happens to be the first
72+ # tool call in an xdist worker.
73+ desktop = tmp_path / "Desktop"
74+ desktop .mkdir ()
75+ (desktop / "file1.txt" ).touch ()
76+ (desktop / "file2.txt" ).touch ()
77+ monkeypatch .setattr (Path , "home" , lambda : tmp_path )
7478
7579 from examples .mcpserver .desktop import mcp
7680
@@ -85,15 +89,8 @@ async def test_desktop(monkeypatch: pytest.MonkeyPatch):
8589 content = result .contents [0 ]
8690 assert isinstance (content , TextResourceContents )
8791 assert isinstance (content .text , str )
88- if sys .platform == "win32" : # pragma: no cover
89- file_1 = "/fake/path/file1.txt" .replace ("/" , "\\ \\ " ) # might be a bug
90- file_2 = "/fake/path/file2.txt" .replace ("/" , "\\ \\ " ) # might be a bug
91- assert file_1 in content .text
92- assert file_2 in content .text
93- # might be a bug, but the test is passing
94- else : # pragma: lax no cover
95- assert "/fake/path/file1.txt" in content .text
96- assert "/fake/path/file2.txt" in content .text
92+ assert "file1.txt" in content .text
93+ assert "file2.txt" in content .text
9794
9895
9996# TODO(v2): Change back to README.md when v2 is released
0 commit comments