Skip to content

Commit 05f0b17

Browse files
committed
Test: Add coverage for invalid session usage
1 parent 6ba5675 commit 05f0b17

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/client/test_session.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,3 +768,20 @@ async def mock_server():
768768
await session.initialize()
769769

770770
await session.call_tool(name=mocked_tool.name, arguments={"foo": "bar"}, meta=meta)
771+
772+
773+
@pytest.mark.anyio
774+
async def test_initialize_without_context_manager_raises_error():
775+
"""
776+
Test that calling initialize() without entering the context manager raises RuntimeError.
777+
"""
778+
# Create dummy streams for session initialization
779+
read_stream, write_stream = anyio.create_memory_object_stream(0)
780+
781+
async with read_stream, write_stream:
782+
# Instantiate the session object directly
783+
session = ClientSession(read_stream, write_stream)
784+
785+
# Verify that calling initialize() raises a RuntimeError
786+
with pytest.raises(RuntimeError, match="must be used within"):
787+
await session.initialize()

0 commit comments

Comments
 (0)