Skip to content

Commit e72299a

Browse files
committed
Adding unit tests
1 parent a2db43a commit e72299a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/mcp/test_resources_server.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import pytest
22
from pydantic import AnyUrl
33

4+
from agents import Agent, Runner
5+
46
from .helpers import FakeMCPServer
57

68

@@ -43,3 +45,27 @@ async def test_read_resource_not_found():
4345
uri = "docs://api/reference"
4446
with pytest.raises(KeyError, match=f"Resource {uri} not found"):
4547
await server.read_resource(AnyUrl(uri))
48+
49+
@pytest.mark.asyncio
50+
@pytest.mark.parametrize("streaming", [False, True])
51+
async def test_agent_with_resources(streaming: bool):
52+
"""Test agent with resources"""
53+
server = FakeMCPServer()
54+
55+
agent = Agent(
56+
name="Assistant",
57+
instructions="Answer users queries using the available resources",
58+
mcp_servers=[server],
59+
)
60+
61+
message = "What's the process to access the APIs? What are the available endpoints?"
62+
if streaming:
63+
streaming_result = Runner.run_streamed(agent, input=message)
64+
async for _ in streaming_result.stream_events():
65+
pass
66+
final_result = streaming_result.final_output
67+
else:
68+
result = await Runner.run(agent, input=message)
69+
final_result = result.final_output
70+
71+
assert final_result is not None

0 commit comments

Comments
 (0)