forked from CoplayDev/unity-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
127 lines (87 loc) · 3.61 KB
/
conftest.py
File metadata and controls
127 lines (87 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import os
import sys
import types
from pathlib import Path
SERVER_ROOT = Path(__file__).resolve().parents[2]
if str(SERVER_ROOT) not in sys.path:
sys.path.insert(0, str(SERVER_ROOT))
SERVER_SRC = SERVER_ROOT / "src"
if str(SERVER_SRC) not in sys.path:
sys.path.insert(0, str(SERVER_SRC))
# Ensure telemetry is disabled during test collection and execution to avoid
# any background network or thread startup that could slow or block pytest.
os.environ.setdefault("DISABLE_TELEMETRY", "true")
os.environ.setdefault("UNITY_MCP_DISABLE_TELEMETRY", "true")
os.environ.setdefault("MCP_DISABLE_TELEMETRY", "true")
# NOTE: These tests are integration tests for the MCP server Python code.
# They test tools, resources, and utilities without requiring Unity to be running.
# Tests can now import directly from the parent package since they're inside src/
# To run: cd Server && uv run pytest tests/integration/ -v
# Stub telemetry modules to avoid file I/O during import of tools package
telemetry = types.ModuleType("telemetry")
def _noop(*args, **kwargs):
pass
class MilestoneType:
pass
telemetry.record_resource_usage = _noop
telemetry.record_tool_usage = _noop
telemetry.record_milestone = _noop
telemetry.MilestoneType = MilestoneType
telemetry.get_package_version = lambda: "0.0.0"
sys.modules.setdefault("telemetry", telemetry)
telemetry_decorator = types.ModuleType("telemetry_decorator")
def _noop_decorator(*_dargs, **_dkwargs):
def _wrap(fn):
return fn
return _wrap
telemetry_decorator.telemetry_tool = _noop_decorator
telemetry_decorator.telemetry_resource = _noop_decorator
sys.modules.setdefault("telemetry_decorator", telemetry_decorator)
# Stub fastmcp module (not mcp.server.fastmcp)
fastmcp = types.ModuleType("fastmcp")
class _DummyFastMCP:
pass
class _DummyContext:
pass
class _DummyMiddleware:
"""Base middleware class stub."""
pass
class _DummyMiddlewareContext:
"""Middleware context stub."""
pass
fastmcp.FastMCP = _DummyFastMCP
fastmcp.Context = _DummyContext
sys.modules.setdefault("fastmcp", fastmcp)
# Stub fastmcp.server.middleware submodule
fastmcp_server = types.ModuleType("fastmcp.server")
fastmcp_server_middleware = types.ModuleType("fastmcp.server.middleware")
fastmcp_server_middleware.Middleware = _DummyMiddleware
fastmcp_server_middleware.MiddlewareContext = _DummyMiddlewareContext
fastmcp.server = fastmcp_server
fastmcp_server.middleware = fastmcp_server_middleware
sys.modules.setdefault("fastmcp.server", fastmcp_server)
sys.modules.setdefault("fastmcp.server.middleware", fastmcp_server_middleware)
# Stub minimal starlette modules to avoid optional dependency imports.
starlette = types.ModuleType("starlette")
starlette_endpoints = types.ModuleType("starlette.endpoints")
starlette_websockets = types.ModuleType("starlette.websockets")
starlette_requests = types.ModuleType("starlette.requests")
starlette_responses = types.ModuleType("starlette.responses")
class _DummyWebSocketEndpoint:
pass
class _DummyWebSocket:
pass
class _DummyRequest:
pass
class _DummyJSONResponse:
def __init__(self, *args, **kwargs):
pass
starlette_endpoints.WebSocketEndpoint = _DummyWebSocketEndpoint
starlette_websockets.WebSocket = _DummyWebSocket
starlette_requests.Request = _DummyRequest
starlette_responses.JSONResponse = _DummyJSONResponse
sys.modules.setdefault("starlette", starlette)
sys.modules.setdefault("starlette.endpoints", starlette_endpoints)
sys.modules.setdefault("starlette.websockets", starlette_websockets)
sys.modules.setdefault("starlette.requests", starlette_requests)
sys.modules.setdefault("starlette.responses", starlette_responses)