Skip to content

Commit a10f945

Browse files
committed
test
1 parent c7b5053 commit a10f945

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/agents/run.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
DEFAULT_RUNNER: Runner | None = None
5050

5151

52-
def set_default_runner(runner: Runner) -> None:
52+
def set_default_runner(runner: Runner | None) -> None:
5353
"""
5454
Set the default runner to use for the agent run.
5555
"""
@@ -146,7 +146,7 @@ def run_sync_impl(
146146
pass
147147

148148
@abc.abstractmethod
149-
def run_streaming_impl(
149+
def run_streamed_impl(
150150
self,
151151
starting_agent: Agent[TContext],
152152
input: str | list[TResponseInputItem],
@@ -297,7 +297,7 @@ def run_streamed(
297297
A result object that contains data about the run, as well as a method to stream events.
298298
"""
299299
runner = DEFAULT_RUNNER or DefaultRunner()
300-
return runner.run_streaming_impl(
300+
return runner.run_streamed_impl(
301301
starting_agent,
302302
input,
303303
context=context,
@@ -511,7 +511,7 @@ def run_sync_impl(
511511
)
512512
)
513513

514-
def run_streaming_impl(
514+
def run_streamed_impl(
515515
self,
516516
starting_agent: Agent[TContext],
517517
input: str | list[TResponseInputItem],

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from agents.models import _openai_shared
66
from agents.models.openai_chatcompletions import OpenAIChatCompletionsModel
77
from agents.models.openai_responses import OpenAIResponsesModel
8+
from agents.run import set_default_runner
89
from agents.tracing import set_trace_processors
910
from agents.tracing.setup import GLOBAL_TRACE_PROVIDER
1011

@@ -33,6 +34,11 @@ def clear_openai_settings():
3334
_openai_shared._use_responses_by_default = True
3435

3536

37+
@pytest.fixture(autouse=True)
38+
def clear_default_runner():
39+
set_default_runner(None)
40+
41+
3642
# This fixture will run after all tests end
3743
@pytest.fixture(autouse=True, scope="session")
3844
def shutdown_trace_provider():

tests/test_run.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from __future__ import annotations
2+
3+
from unittest import mock
4+
5+
import pytest
6+
7+
from agents import Agent, Runner
8+
from agents.run import set_default_runner
9+
10+
from .fake_model import FakeModel
11+
12+
13+
@pytest.mark.asyncio
14+
async def test_static_run_methods_call_into_default_runner() -> None:
15+
runner = mock.Mock(spec=Runner)
16+
set_default_runner(runner)
17+
18+
agent = Agent(name="test", model=FakeModel())
19+
await Runner.run(agent, input="test")
20+
runner.run_impl.assert_called_once()
21+
22+
Runner.run_streamed(agent, input="test")
23+
runner.run_streamed_impl.assert_called_once()
24+
25+
Runner.run_sync(agent, input="test")
26+
runner.run_sync_impl.assert_called_once()

0 commit comments

Comments
 (0)