Skip to content

Commit c0c6833

Browse files
committed
fix: rename TestInstrumenter to MockInstrumenter to avoid pytest collection
Pytest was trying to collect TestInstrumenter as a test class because it starts with 'Test', but it's actually a helper class with an __init__ constructor. Renaming to MockInstrumenter resolves the PytestCollectionWarning.
1 parent c6bcdb5 commit c0c6833

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

tests/shared/test_instrumentation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from mcp.shared.instrumentation import NoOpInstrumenter, get_default_instrumenter
66

77

8-
class TestInstrumenter:
8+
class MockInstrumenter:
99
"""Track calls to instrumentation hooks for testing."""
1010

1111
def __init__(self):
@@ -75,8 +75,8 @@ def test_get_default_instrumenter():
7575

7676

7777
def test_instrumenter_protocol():
78-
"""Test that TestInstrumenter implements the Instrumenter protocol."""
79-
instrumenter = TestInstrumenter()
78+
"""Test that MockInstrumenter implements the Instrumenter protocol."""
79+
instrumenter = MockInstrumenter()
8080

8181
# Call all methods to ensure they exist
8282
token = instrumenter.on_request_start(request_id=1, request_type="TestRequest", method="test_method")
@@ -94,7 +94,7 @@ def test_instrumenter_protocol():
9494

9595
def test_instrumenter_tracks_request_id():
9696
"""Test that request_id is tracked consistently across hooks."""
97-
instrumenter = TestInstrumenter()
97+
instrumenter = MockInstrumenter()
9898
test_request_id = 42
9999

100100
token = instrumenter.on_request_start(request_id=test_request_id, request_type="TestRequest")
@@ -108,7 +108,7 @@ def test_instrumenter_tracks_request_id():
108108

109109
def test_instrumenter_metadata():
110110
"""Test that metadata is passed through correctly."""
111-
instrumenter = TestInstrumenter()
111+
instrumenter = MockInstrumenter()
112112

113113
instrumenter.on_request_start(
114114
request_id=1, request_type="TestRequest", method="test_tool", session_type="server", custom_field="custom_value"
@@ -122,7 +122,7 @@ def test_instrumenter_metadata():
122122

123123
def test_instrumenter_duration_tracking():
124124
"""Test that duration is passed to on_request_end."""
125-
instrumenter = TestInstrumenter()
125+
instrumenter = MockInstrumenter()
126126

127127
token = {"test": "token"}
128128
instrumenter.on_request_end(
@@ -136,7 +136,7 @@ def test_instrumenter_duration_tracking():
136136

137137
def test_instrumenter_error_info():
138138
"""Test that error information is captured correctly."""
139-
instrumenter = TestInstrumenter()
139+
instrumenter = MockInstrumenter()
140140
test_error = ValueError("test error message")
141141

142142
token = {"test": "token"}
@@ -153,7 +153,7 @@ def test_instrumenter_error_info():
153153

154154
def test_instrumenter_token_flow():
155155
"""Test that token is passed correctly from start to end/error."""
156-
instrumenter = TestInstrumenter()
156+
instrumenter = MockInstrumenter()
157157

158158
# Start request and get token
159159
token = instrumenter.on_request_start(request_id=1, request_type="TestRequest", method="test_tool")

0 commit comments

Comments
 (0)