Skip to content

Commit 0de100f

Browse files
cleanup fixture spaghetti
1 parent f6595ca commit 0de100f

File tree

4 files changed

+25
-104
lines changed

4 files changed

+25
-104
lines changed

tests/conftest.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,8 @@ def event_loop():
3737
loop.close()
3838

3939

40-
@pytest.fixture
41-
def plugins():
42-
# By default, no plugins.
43-
# Other tests can override this fixture, such as in tests/openai_agents/conftest.py
44-
return []
45-
46-
47-
@pytest_asyncio.fixture
48-
async def env(request, plugins) -> AsyncGenerator[WorkflowEnvironment, None]:
40+
@pytest_asyncio.fixture(scope="session")
41+
async def env(request) -> AsyncGenerator[WorkflowEnvironment, None]:
4942
env_type = request.config.getoption("--workflow-environment")
5043
if env_type == "local":
5144
env = await WorkflowEnvironment.start_local(
@@ -54,15 +47,12 @@ async def env(request, plugins) -> AsyncGenerator[WorkflowEnvironment, None]:
5447
"frontend.enableExecuteMultiOperation=true",
5548
"--dynamic-config-value",
5649
"system.enableEagerWorkflowStart=true",
57-
],
58-
plugins=plugins,
50+
]
5951
)
6052
elif env_type == "time-skipping":
6153
env = await WorkflowEnvironment.start_time_skipping()
6254
else:
63-
env = WorkflowEnvironment.from_client(
64-
await Client.connect(env_type, plugins=plugins)
65-
)
55+
env = WorkflowEnvironment.from_client(await Client.connect(env_type))
6656
yield env
6757
await env.shutdown()
6858

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,18 @@
11
import uuid
22
from concurrent.futures import ThreadPoolExecutor
33

4-
import pytest
5-
from agents import ModelResponse, Usage
6-
from openai.types.responses import ResponseOutputMessage, ResponseOutputText
74
from temporalio.client import Client
85
from temporalio.worker import Worker
6+
from temporalio.contrib.openai_agents.testing import (
7+
AgentEnvironment,
8+
ResponseBuilders,
9+
TestModel,
10+
)
911

1012
from openai_agents.basic.workflows.hello_world_workflow import HelloWorldAgent
11-
from tests.openai_agents.conftest import sequential_test_model
1213

1314

14-
@pytest.fixture
15-
def test_model():
16-
return sequential_test_model(
17-
[
18-
ModelResponse(
19-
output=[
20-
ResponseOutputMessage(
21-
id="1",
22-
content=[
23-
ResponseOutputText(
24-
annotations=[],
25-
text="This is a haiku (not really)",
26-
type="output_text",
27-
)
28-
],
29-
role="assistant",
30-
status="completed",
31-
type="message",
32-
)
33-
],
34-
usage=Usage(
35-
requests=1, input_tokens=1, output_tokens=1, total_tokens=1
36-
),
37-
response_id="1",
38-
)
39-
]
40-
)
41-
42-
43-
@pytest.fixture
44-
def test_model():
15+
def haiku_test_model():
4516
return TestModel.returning_responses(
4617
[ResponseBuilders.output_message("This is a haiku (not really)")]
4718
)
@@ -50,17 +21,19 @@ def test_model():
5021
async def test_execute_workflow(client: Client):
5122
task_queue_name = str(uuid.uuid4())
5223

53-
async with Worker(
54-
client,
55-
task_queue=task_queue_name,
56-
workflows=[HelloWorldAgent],
57-
activity_executor=ThreadPoolExecutor(5),
58-
):
59-
result = await client.execute_workflow(
60-
HelloWorldAgent.run,
61-
"Write a recursive haiku about recursive haikus.",
62-
id=str(uuid.uuid4()),
24+
async with AgentEnvironment(model=haiku_test_model()) as agent_env:
25+
client = agent_env.applied_on_client(client)
26+
async with Worker(
27+
client,
6328
task_queue=task_queue_name,
64-
)
65-
assert isinstance(result, str)
66-
assert len(result) > 0
29+
workflows=[HelloWorldAgent],
30+
activity_executor=ThreadPoolExecutor(5),
31+
):
32+
result = await client.execute_workflow(
33+
HelloWorldAgent.run,
34+
"Write a recursive haiku about recursive haikus.",
35+
id=str(uuid.uuid4()),
36+
task_queue=task_queue_name,
37+
)
38+
assert isinstance(result, str)
39+
assert len(result) > 0

tests/openai_agents/conftest.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

tests/openai_agents/e2e/conftest.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)