Skip to content

Commit 233f368

Browse files
committed
fix: use proper StreamableHTTPTransport initialization in tests
Use StreamableHTTPTransport(url) instead of __new__() to avoid AttributeError on uninitialized attributes.
1 parent b6f7fb2 commit 233f368

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

tests/client/test_non2xx_status.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ def _make_request_context(self, request_id: str = "test-123") -> MagicMock:
3030
ctx.metadata = None
3131
return ctx
3232

33+
def _make_transport(self) -> StreamableHTTPTransport:
34+
"""Create a StreamableHTTPTransport for testing."""
35+
return StreamableHTTPTransport("http://test/mcp")
36+
3337
@pytest.mark.anyio
3438
async def test_401_produces_error_response(self):
3539
"""401 Unauthorized should produce a JSONRPCError with the request's ID."""
36-
# This test verifies the fix for #3091
37-
# When server returns 401, caller should get a proper error, not a timeout
38-
transport = StreamableHTTPTransport.__new__(StreamableHTTPTransport)
39-
transport.url = "http://test"
40-
transport.session_id = None
40+
transport = self._make_transport()
4141

4242
ctx = self._make_request_context()
4343

@@ -67,9 +67,7 @@ async def test_401_produces_error_response(self):
6767
@pytest.mark.anyio
6868
async def test_403_produces_error_response(self):
6969
"""403 Forbidden should produce a JSONRPCError with the request's ID."""
70-
transport = StreamableHTTPTransport.__new__(StreamableHTTPTransport)
71-
transport.url = "http://test"
72-
transport.session_id = None
70+
transport = self._make_transport()
7371

7472
ctx = self._make_request_context()
7573

@@ -93,9 +91,7 @@ async def test_403_produces_error_response(self):
9391
@pytest.mark.anyio
9492
async def test_500_produces_error_response(self):
9593
"""500 Internal Server Error should produce a JSONRPCError."""
96-
transport = StreamableHTTPTransport.__new__(StreamableHTTPTransport)
97-
transport.url = "http://test"
98-
transport.session_id = None
94+
transport = self._make_transport()
9995

10096
ctx = self._make_request_context()
10197

@@ -118,9 +114,7 @@ async def test_500_produces_error_response(self):
118114
@pytest.mark.anyio
119115
async def test_json_error_body_is_parsed(self):
120116
"""When server returns JSON-RPC error body, it should be used directly."""
121-
transport = StreamableHTTPTransport.__new__(StreamableHTTPTransport)
122-
transport.url = "http://test"
123-
transport.session_id = None
117+
transport = self._make_transport()
124118

125119
ctx = self._make_request_context()
126120

0 commit comments

Comments
 (0)