Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
version: 0.7.2

- name: Install the project
run: uv sync --frozen --all-extras --python ${{ matrix.python-version }} --resolution ${{ matrix.dep-resolution }}
run: uv sync --all-extras --python ${{ matrix.python-version }} --resolution ${{ matrix.dep-resolution }}

- name: Run pytest
run: uv run --frozen --no-sync pytest
Expand Down
27 changes: 22 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ dev = [
"pytest-pretty>=1.2.0",
"inline-snapshot>=0.23.0",
"dirty-equals>=0.9.0",
"coverage[toml]>7.10.3",
]
docs = [
"mkdocs>=1.6.1",
Expand Down Expand Up @@ -142,11 +143,6 @@ mcp = { workspace = true }
[tool.pytest.ini_options]
log_cli = true
xfail_strict = true
addopts = """
--color=yes
--capture=fd
--numprocesses auto
"""
filterwarnings = [
"error",
# This should be fixed on Uvicorn's side.
Expand All @@ -166,3 +162,24 @@ MD029=false # ol-prefix - Ordered list item prefix
MD033=false # no-inline-html Inline HTML
MD041=false # first-line-heading/first-line-h1
MD059=false # descriptive-link-text

# https://coverage.readthedocs.io/en/latest/config.html#run
[tool.coverage.run]
branch = true
patch = ["subprocess"]
concurrency = ["multiprocessing", "thread"]
source = ["src", "tests"]

# https://coverage.readthedocs.io/en/latest/config.html#report
[tool.coverage.report]
fail_under = 100
skip_covered = true
show_missing = true
ignore_errors = true
precision = 2
exclude_lines = [
"pragma: no cover",
"if TYPE_CHECKING:",
"@overload",
"raise NotImplementedError",
]
7 changes: 7 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

set -ex

uv run coverage run -m pytest -n auto $@
uv run coverage combine
uv run coverage report
37 changes: 21 additions & 16 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
"""Tests for example servers"""

# TODO(Marcelo): The `examples` directory needs to be importable as a package.
# pyright: reportMissingImports=false
# pyright: reportUnknownVariableType=false
# pyright: reportUnknownArgumentType=false
# pyright: reportUnknownMemberType=false

import sys
from pathlib import Path

import pytest
from pydantic import AnyUrl
from pytest_examples import CodeExample, EvalExample, find_examples

from examples.fastmcp.desktop import mcp
from mcp.shared.memory import create_connected_server_and_client_session as client_session
from mcp.types import TextContent, TextResourceContents

Expand Down Expand Up @@ -45,13 +48,23 @@ async def test_complex_inputs():


@pytest.mark.anyio
async def test_desktop(monkeypatch: pytest.MonkeyPatch):
@pytest.mark.parametrize(
"files",
[
pytest.param(
["/fake/path/file1.txt", "/fake/path/file2.txt"],
id="unix",
marks=pytest.mark.skipif(sys.platform == "win32", reason="Unix-specific test"),
),
pytest.param(
["C:\\fake\\path\\file1.txt", "C:\\fake\\path\\file2.txt"],
id="windows",
marks=pytest.mark.skipif(sys.platform != "win32", reason="Windows-specific test"),
),
],
)
async def test_desktop(monkeypatch: pytest.MonkeyPatch, files: list[str]):
"""Test the desktop server"""
from pathlib import Path

from pydantic import AnyUrl

from examples.fastmcp.desktop import mcp

# Mock desktop directory listing
mock_files = [Path("/fake/path/file1.txt"), Path("/fake/path/file2.txt")]
Expand All @@ -72,15 +85,7 @@ async def test_desktop(monkeypatch: pytest.MonkeyPatch):
content = result.contents[0]
assert isinstance(content, TextResourceContents)
assert isinstance(content.text, str)
if sys.platform == "win32":
file_1 = "/fake/path/file1.txt".replace("/", "\\\\") # might be a bug
file_2 = "/fake/path/file2.txt".replace("/", "\\\\") # might be a bug
assert file_1 in content.text
assert file_2 in content.text
# might be a bug, but the test is passing
else:
assert "/fake/path/file1.txt" in content.text
assert "/fake/path/file2.txt" in content.text
assert all(file in content.text for file in files)


@pytest.mark.parametrize("example", find_examples("README.md"), ids=str)
Expand Down
Loading
Loading