Skip to content

Commit 87f88e3

Browse files
authored
Update test_run_config_inheritance.py
1 parent f3a6fe0 commit 87f88e3

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

tests/test_run_config_inheritance.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import pytest
66

77
from agents import Agent, RunConfig, Runner
8+
from agents.run import get_current_run_config, reset_current_run_config, set_current_run_config
89
from agents.tool import function_tool
9-
from agents.tracing.scope import Scope
1010

1111
from .fake_model import FakeModel
1212
from .test_responses import get_function_tool_call, get_text_message
@@ -20,7 +20,7 @@ async def test_run_config_inheritance_enabled():
2020
@function_tool
2121
async def config_capture_tool() -> str:
2222
"""Tool that captures the current run config"""
23-
current_config = Scope.get_current_run_config()
23+
current_config = get_current_run_config()
2424
inherited_configs.append(current_config)
2525
return "config_captured"
2626

@@ -44,7 +44,9 @@ async def config_capture_tool() -> str:
4444
instructions="You are a parent agent",
4545
model=FakeModel(),
4646
tools=[
47-
sub_agent.as_tool(tool_name="sub_agent_tool", tool_description="Call the sub agent")
47+
sub_agent.as_tool(
48+
tool_name="sub_agent_tool", tool_description="Call the sub agent"
49+
)
4850
],
4951
)
5052

@@ -58,15 +60,15 @@ async def config_capture_tool() -> str:
5860

5961
run_config = RunConfig(pass_run_config_to_sub_agents=True)
6062

61-
assert Scope.get_current_run_config() is None
63+
assert get_current_run_config() is None
6264

6365
await Runner.run(
6466
starting_agent=parent_agent,
6567
input="Use the sub agent tool",
6668
run_config=run_config,
6769
)
6870

69-
assert Scope.get_current_run_config() is None
71+
assert get_current_run_config() is None
7072
assert len(inherited_configs) == 1
7173
assert inherited_configs[0] is run_config
7274
assert inherited_configs[0].pass_run_config_to_sub_agents is True
@@ -80,7 +82,7 @@ async def test_run_config_inheritance_disabled():
8082
@function_tool
8183
async def config_capture_tool() -> str:
8284
"""Tool that captures the current run config"""
83-
current_config = Scope.get_current_run_config()
85+
current_config = get_current_run_config()
8486
inherited_configs.append(current_config)
8587
return "config_captured"
8688

@@ -104,7 +106,9 @@ async def config_capture_tool() -> str:
104106
instructions="You are a parent agent",
105107
model=FakeModel(),
106108
tools=[
107-
sub_agent.as_tool(tool_name="sub_agent_tool", tool_description="Call the sub agent")
109+
sub_agent.as_tool(
110+
tool_name="sub_agent_tool", tool_description="Call the sub agent"
111+
)
108112
],
109113
)
110114

@@ -124,7 +128,7 @@ async def config_capture_tool() -> str:
124128
run_config=run_config,
125129
)
126130

127-
assert Scope.get_current_run_config() is None
131+
assert get_current_run_config() is None
128132
assert len(inherited_configs) == 1
129133
assert inherited_configs[0] is None
130134

@@ -143,7 +147,7 @@ async def test_context_variable_cleanup_on_error():
143147

144148
run_config = RunConfig(pass_run_config_to_sub_agents=True)
145149

146-
assert Scope.get_current_run_config() is None
150+
assert get_current_run_config() is None
147151

148152
with pytest.raises(RuntimeError, match="Intentional test failure"):
149153
await Runner.run(
@@ -152,22 +156,22 @@ async def test_context_variable_cleanup_on_error():
152156
run_config=run_config,
153157
)
154158

155-
assert Scope.get_current_run_config() is None
159+
assert get_current_run_config() is None
156160

157161

158162
@pytest.mark.asyncio
159163
async def test_scope_methods_directly():
160164
"""Test the Scope class methods directly for RunConfig management"""
161165
run_config = RunConfig(pass_run_config_to_sub_agents=True)
162166

163-
assert Scope.get_current_run_config() is None
167+
assert get_current_run_config() is None
164168

165-
token = Scope.set_current_run_config(run_config)
166-
assert Scope.get_current_run_config() is run_config
169+
token = set_current_run_config(run_config)
170+
assert get_current_run_config() is run_config
167171

168-
Scope.reset_current_run_config(token)
169-
assert Scope.get_current_run_config() is None
172+
reset_current_run_config(token)
173+
assert get_current_run_config() is None
170174

171-
token = Scope.set_current_run_config(None)
172-
assert Scope.get_current_run_config() is None
173-
Scope.reset_current_run_config(token)
175+
token = set_current_run_config(None)
176+
assert get_current_run_config() is None
177+
reset_current_run_config(token)

0 commit comments

Comments
 (0)