File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff 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 ()
You can’t perform that action at this time.
0 commit comments