Skip to content

Commit d90de08

Browse files
authored
Merge pull request #47 from jlowin/warning-and-flake
fix warning and flake
2 parents f03184b + e383d5d commit d90de08

File tree

4 files changed

+93
-56
lines changed

4 files changed

+93
-56
lines changed

Diff for: pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ tests = [
2727
"pre-commit",
2828
"pytest>=8.3.3",
2929
"pytest-asyncio>=0.23.5",
30+
"pytest-flakefinder",
3031
"pytest-xdist>=3.6.1",
3132
"ruff",
3233
]

Diff for: tests/test_cli.py

+45-39
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import json
44
import sys
55
from pathlib import Path
6-
from unittest.mock import patch, call
6+
from unittest.mock import call, patch
77

88
import pytest
99
from typer.testing import CliRunner
1010

11-
from fastmcp.cli.cli import app, _parse_env_var, _parse_file_path
11+
from fastmcp.cli.cli import _parse_env_var, _parse_file_path, app
1212

1313

1414
@pytest.fixture
@@ -297,47 +297,53 @@ def test_dev_with_dependencies(mock_config, server_file):
297297
assert mock_run.call_args_list[0] == call(
298298
["npx.cmd", "--version"], check=True, capture_output=True, shell=True
299299
)
300-
assert mock_run.call_args_list[1] == call(
301-
[
302-
"npx.cmd",
303-
"@modelcontextprotocol/inspector",
304-
"uv",
305-
"run",
306-
"--with",
307-
"fastmcp",
308-
"--with",
309-
"numpy",
310-
"--with",
311-
"pandas",
312-
"fastmcp",
313-
"run",
314-
str(server_file),
315-
],
316-
check=True,
317-
shell=True,
300+
301+
# get the actual command and expected command without dependencies
302+
actual_cmd = mock_run.call_args_list[1][0][0]
303+
expected_start = [
304+
"npx.cmd",
305+
"@modelcontextprotocol/inspector",
306+
"uv",
307+
"run",
308+
"--with",
309+
"fastmcp",
310+
]
311+
expected_end = ["fastmcp", "run", str(server_file)]
312+
313+
# verify start and end of command
314+
assert actual_cmd[: len(expected_start)] == expected_start
315+
assert actual_cmd[-len(expected_end) :] == expected_end
316+
317+
# verify dependencies are present (order-independent)
318+
deps_section = actual_cmd[len(expected_start) : -len(expected_end)]
319+
assert all(
320+
x in deps_section for x in ["--with", "numpy", "--with", "pandas"]
318321
)
322+
323+
assert mock_run.call_args_list[1][1] == {"check": True, "shell": True}
319324
else:
320-
# On Unix, expect one call
321-
mock_run.assert_called_once_with(
322-
[
323-
"npx",
324-
"@modelcontextprotocol/inspector",
325-
"uv",
326-
"run",
327-
"--with",
328-
"fastmcp",
329-
"--with",
330-
"numpy",
331-
"--with",
332-
"pandas",
333-
"fastmcp",
334-
"run",
335-
str(server_file),
336-
],
337-
check=True,
338-
shell=False, # Note: shell=False on Unix
325+
# same verification for unix, just with different command prefix
326+
actual_cmd = mock_run.call_args_list[0][0][0]
327+
expected_start = [
328+
"npx",
329+
"@modelcontextprotocol/inspector",
330+
"uv",
331+
"run",
332+
"--with",
333+
"fastmcp",
334+
]
335+
expected_end = ["fastmcp", "run", str(server_file)]
336+
337+
assert actual_cmd[: len(expected_start)] == expected_start
338+
assert actual_cmd[-len(expected_end) :] == expected_end
339+
340+
deps_section = actual_cmd[len(expected_start) : -len(expected_end)]
341+
assert all(
342+
x in deps_section for x in ["--with", "numpy", "--with", "pandas"]
339343
)
340344

345+
assert mock_run.call_args_list[0][1] == {"check": True, "shell": False}
346+
341347

342348
def test_run_with_dependencies(mock_config, server_file):
343349
"""Test that run command does not handle dependencies."""

Diff for: tests/test_func_metadata.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
from pydantic import BaseModel, Field
21
from typing import Annotated
2+
33
import annotated_types
4-
from fastmcp.utilities.func_metadata import func_metadata
54
import pytest
5+
from pydantic import BaseModel, Field
6+
7+
from fastmcp.utilities.func_metadata import func_metadata
68

79

8-
class TestInputModelA(BaseModel):
10+
class SomeInputModelA(BaseModel):
911
pass
1012

1113

12-
class TestInputModelB(BaseModel):
14+
class SomeInputModelB(BaseModel):
1315
class InnerModel(BaseModel):
1416
x: int
1517

@@ -44,15 +46,15 @@ def complex_arguments_fn(
4446
int, Field(1)
4547
],
4648
unannotated,
47-
my_model_a: TestInputModelA,
48-
my_model_a_forward_ref: "TestInputModelA",
49-
my_model_b: TestInputModelB,
49+
my_model_a: SomeInputModelA,
50+
my_model_a_forward_ref: "SomeInputModelA",
51+
my_model_b: SomeInputModelB,
5052
an_int_annotated_with_field_default: Annotated[
5153
int,
5254
Field(1, description="An int with a field"),
5355
],
5456
unannotated_with_default=5,
55-
my_model_a_with_default: TestInputModelA = TestInputModelA(), # noqa: B008
57+
my_model_a_with_default: SomeInputModelA = SomeInputModelA(), # noqa: B008
5658
an_int_with_default: int = 1,
5759
must_be_none_with_default: None = None,
5860
an_int_with_equals_field: int = Field(1, ge=0),
@@ -239,12 +241,12 @@ def test_complex_function_json_schema():
239241
"title": "InnerModel",
240242
"type": "object",
241243
},
242-
"TestInputModelA": {
244+
"SomeInputModelA": {
243245
"properties": {},
244-
"title": "TestInputModelA",
246+
"title": "SomeInputModelA",
245247
"type": "object",
246248
},
247-
"TestInputModelB": {
249+
"SomeInputModelB": {
248250
"properties": {
249251
"how_many_shrimp": {
250252
"description": "How many shrimp in the tank???",
@@ -255,7 +257,7 @@ def test_complex_function_json_schema():
255257
"y": {"title": "Y", "type": "null"},
256258
},
257259
"required": ["how_many_shrimp", "ok", "y"],
258-
"title": "TestInputModelB",
260+
"title": "SomeInputModelB",
259261
"type": "object",
260262
},
261263
},
@@ -299,9 +301,9 @@ def test_complex_function_json_schema():
299301
"type": "integer",
300302
},
301303
"unannotated": {"title": "unannotated", "type": "string"},
302-
"my_model_a": {"$ref": "#/$defs/TestInputModelA"},
303-
"my_model_a_forward_ref": {"$ref": "#/$defs/TestInputModelA"},
304-
"my_model_b": {"$ref": "#/$defs/TestInputModelB"},
304+
"my_model_a": {"$ref": "#/$defs/SomeInputModelA"},
305+
"my_model_a_forward_ref": {"$ref": "#/$defs/SomeInputModelA"},
306+
"my_model_b": {"$ref": "#/$defs/SomeInputModelB"},
305307
"an_int_annotated_with_field_default": {
306308
"default": 1,
307309
"description": "An int with a field",
@@ -314,7 +316,7 @@ def test_complex_function_json_schema():
314316
"type": "string",
315317
},
316318
"my_model_a_with_default": {
317-
"$ref": "#/$defs/TestInputModelA",
319+
"$ref": "#/$defs/SomeInputModelA",
318320
"default": {},
319321
},
320322
"an_int_with_default": {

Diff for: uv.lock

+29-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)