Skip to content

Commit 09d00e4

Browse files
authored
tests: improve the time for some tests (#2592)
1 parent e10cb23 commit 09d00e4

File tree

4 files changed

+5
-116
lines changed

4 files changed

+5
-116
lines changed

tests/providers/cassettes/test_openrouter/test_openrouter_with_google_model.yaml

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,4 @@
11
interactions:
2-
- request:
3-
headers:
4-
accept:
5-
- application/json
6-
accept-encoding:
7-
- gzip, deflate
8-
connection:
9-
- keep-alive
10-
content-length:
11-
- '164'
12-
content-type:
13-
- application/json
14-
host:
15-
- openrouter.ai
16-
method: POST
17-
parsed_body:
18-
messages:
19-
- content: Be helpful.
20-
role: system
21-
- content: Tell me a joke.
22-
role: user
23-
model: google/gemini-2.0-flash-exp:free
24-
n: 1
25-
stream: false
26-
uri: https://openrouter.ai/api/v1/chat/completions
27-
response:
28-
headers:
29-
access-control-allow-origin:
30-
- '*'
31-
connection:
32-
- keep-alive
33-
content-length:
34-
- '242'
35-
content-type:
36-
- application/json
37-
vary:
38-
- Accept-Encoding
39-
parsed_body:
40-
error:
41-
code: 429
42-
message: Provider returned error
43-
metadata:
44-
provider_name: Google
45-
raw: google/gemini-2.0-flash-exp:free is temporarily rate-limited upstream; please retry shortly.
46-
user_id: user_2uRh0l3Yi3hdjBArTOSmLXWJBc4
47-
status:
48-
code: 429
49-
message: Too Many Requests
50-
- request:
51-
headers:
52-
accept:
53-
- application/json
54-
accept-encoding:
55-
- gzip, deflate
56-
connection:
57-
- keep-alive
58-
content-length:
59-
- '164'
60-
content-type:
61-
- application/json
62-
host:
63-
- openrouter.ai
64-
method: POST
65-
parsed_body:
66-
messages:
67-
- content: Be helpful.
68-
role: system
69-
- content: Tell me a joke.
70-
role: user
71-
model: google/gemini-2.0-flash-exp:free
72-
n: 1
73-
stream: false
74-
uri: https://openrouter.ai/api/v1/chat/completions
75-
response:
76-
headers:
77-
access-control-allow-origin:
78-
- '*'
79-
connection:
80-
- keep-alive
81-
content-length:
82-
- '252'
83-
content-type:
84-
- application/json
85-
vary:
86-
- Accept-Encoding
87-
parsed_body:
88-
error:
89-
code: 429
90-
message: Provider returned error
91-
metadata:
92-
provider_name: Google AI Studio
93-
raw: google/gemini-2.0-flash-exp:free is temporarily rate-limited upstream; please retry shortly.
94-
user_id: user_2uRh0l3Yi3hdjBArTOSmLXWJBc4
95-
status:
96-
code: 429
97-
message: Too Many Requests
982
- request:
993
headers:
1004
accept:

tests/test_agent.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4074,9 +4074,7 @@ async def test_implicit_context_manager():
40744074
toolset = CombinedToolset([server1, PrefixedToolset(server2, 'prefix')])
40754075
agent = Agent('test', toolsets=[toolset])
40764076

4077-
async with agent.iter(
4078-
user_prompt='Hello',
4079-
):
4077+
async with agent.iter(user_prompt='Hello'):
40804078
assert server1.is_running
40814079
assert server2.is_running
40824080

tests/test_mcp.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ def test_sse_server_conflicting_timeout_params():
178178
)
179179

180180

181-
@pytest.mark.vcr()
182181
async def test_agent_with_stdio_server(allow_model_requests: None, agent: Agent):
183182
async with agent:
184183
result = await agent.run('What is 0 degrees Celsius in Fahrenheit?')
@@ -280,7 +279,6 @@ def get_none() -> None: # pragma: no cover
280279
await agent.run('No conflict')
281280

282281

283-
@pytest.mark.vcr()
284282
async def test_agent_with_server_not_running(agent: Agent, allow_model_requests: None):
285283
result = await agent.run('What is 0 degrees Celsius in Fahrenheit?')
286284
assert result.output == snapshot('0 degrees Celsius is 32.0 degrees Fahrenheit.')
@@ -306,7 +304,6 @@ async def test_log_level_set(run_context: RunContext[int]):
306304
assert result == snapshot('info')
307305

308306

309-
@pytest.mark.vcr()
310307
async def test_tool_returning_str(allow_model_requests: None, agent: Agent):
311308
async with agent:
312309
result = await agent.run('What is the weather in Mexico City?')
@@ -379,7 +376,6 @@ async def test_tool_returning_str(allow_model_requests: None, agent: Agent):
379376
)
380377

381378

382-
@pytest.mark.vcr()
383379
async def test_tool_returning_text_resource(allow_model_requests: None, agent: Agent):
384380
async with agent:
385381
result = await agent.run('Get me the product name')
@@ -446,7 +442,6 @@ async def test_tool_returning_text_resource(allow_model_requests: None, agent: A
446442
)
447443

448444

449-
@pytest.mark.vcr()
450445
async def test_tool_returning_text_resource_link(allow_model_requests: None, agent: Agent):
451446
async with agent:
452447
result = await agent.run('Get me the product name via get_product_name_link')
@@ -513,7 +508,6 @@ async def test_tool_returning_text_resource_link(allow_model_requests: None, age
513508
)
514509

515510

516-
@pytest.mark.vcr()
517511
async def test_tool_returning_image_resource(allow_model_requests: None, agent: Agent, image_content: BinaryContent):
518512
async with agent:
519513
result = await agent.run('Get me the image resource')
@@ -587,7 +581,6 @@ async def test_tool_returning_image_resource(allow_model_requests: None, agent:
587581
)
588582

589583

590-
@pytest.mark.vcr()
591584
async def test_tool_returning_image_resource_link(
592585
allow_model_requests: None, agent: Agent, image_content: BinaryContent
593586
):
@@ -663,7 +656,6 @@ async def test_tool_returning_image_resource_link(
663656
)
664657

665658

666-
@pytest.mark.vcr()
667659
async def test_tool_returning_audio_resource(
668660
allow_model_requests: None, agent: Agent, audio_content: BinaryContent, gemini_api_key: str
669661
):
@@ -712,7 +704,6 @@ async def test_tool_returning_audio_resource(
712704
)
713705

714706

715-
@pytest.mark.vcr()
716707
async def test_tool_returning_audio_resource_link(
717708
allow_model_requests: None, agent: Agent, audio_content: BinaryContent, gemini_api_key: str
718709
):
@@ -771,7 +762,6 @@ async def test_tool_returning_audio_resource_link(
771762
)
772763

773764

774-
@pytest.mark.vcr()
775765
async def test_tool_returning_image(allow_model_requests: None, agent: Agent, image_content: BinaryContent):
776766
async with agent:
777767
result = await agent.run('Get me an image')
@@ -845,7 +835,6 @@ async def test_tool_returning_image(allow_model_requests: None, agent: Agent, im
845835
)
846836

847837

848-
@pytest.mark.vcr()
849838
async def test_tool_returning_dict(allow_model_requests: None, agent: Agent):
850839
async with agent:
851840
result = await agent.run('Get me a dict, respond on one line')
@@ -906,7 +895,6 @@ async def test_tool_returning_dict(allow_model_requests: None, agent: Agent):
906895
)
907896

908897

909-
@pytest.mark.vcr()
910898
async def test_tool_returning_error(allow_model_requests: None, agent: Agent):
911899
async with agent:
912900
result = await agent.run('Get me an error, pass False as a value, unless the tool tells you otherwise')
@@ -1011,7 +999,6 @@ async def test_tool_returning_error(allow_model_requests: None, agent: Agent):
1011999
)
10121000

10131001

1014-
@pytest.mark.vcr()
10151002
async def test_tool_returning_none(allow_model_requests: None, agent: Agent):
10161003
async with agent:
10171004
result = await agent.run('Call the none tool and say Hello')
@@ -1072,7 +1059,6 @@ async def test_tool_returning_none(allow_model_requests: None, agent: Agent):
10721059
)
10731060

10741061

1075-
@pytest.mark.vcr()
10761062
async def test_tool_returning_multiple_items(allow_model_requests: None, agent: Agent, image_content: BinaryContent):
10771063
async with agent:
10781064
result = await agent.run('Get me multiple items and summarize in one sentence')

tests/test_tenacity.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ def validate_response(response: httpx.Response):
553553

554554
controller = Retrying(
555555
retry=retry_if_exception_type(httpx.HTTPStatusError),
556-
wait=wait_retry_after(max_wait=2), # Cap at 2 seconds for tests
556+
wait=wait_retry_after(max_wait=0.1), # Cap at 0.1 seconds for tests
557557
stop=stop_after_attempt(3),
558558
reraise=True,
559559
)
@@ -568,5 +568,6 @@ def validate_response(response: httpx.Response):
568568

569569
assert result is mock_response_success
570570
assert mock_transport.handle_request.call_count == 2
571-
# Should have waited approximately 2 seconds (capped by max_wait)
572-
assert 1.8 <= (end_time - start_time) <= 3.0
571+
# Should have waited approximately 0.2 seconds (capped by max_wait)
572+
duration = end_time - start_time
573+
assert 0.1 <= duration <= 0.2

0 commit comments

Comments
 (0)