Skip to content

Commit 0e6e808

Browse files
test(openai-agents): Remove MagicMock from mocked ModelResponse (#5126)
Remove the `function` property from tool calls in mocked model responses. `openai-agents` commit `a776d80` broke our test suite because instances of `ResponseFunctionToolCall` are now serialized inside `openai-agents`. As we attach a non-serializable `MagicMock` as the `function` attribute to the instances, our test suite faced an unhandled exception starting with `openai-agents` version 0.6.0. The model `ResponseFunctionToolCall` does not declare a function field. Closes #5124
1 parent c63e8d8 commit 0e6e808

File tree

5 files changed

+6
-26
lines changed

5 files changed

+6
-26
lines changed

scripts/populate_tox/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@
285285
"*": ["pytest-asyncio"],
286286
},
287287
"python": ">=3.10",
288-
"include": "!=0.6.0,!=0.6.1",
289288
},
290289
"openfeature": {
291290
"package": "openfeature-sdk",

scripts/populate_tox/package_dependencies.jsonl

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

scripts/populate_tox/releases.jsonl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
{"info": {"classifiers": ["Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.9", "Topic :: Software Development :: Libraries :: Python Modules", "Typing :: Typed"], "name": "openai-agents", "requires_python": ">=3.9", "version": "0.0.19", "yanked": false}, "urls": [{"packagetype": "bdist_wheel", "filename": "openai_agents-0.0.19-py3-none-any.whl"}, {"packagetype": "sdist", "filename": "openai_agents-0.0.19.tar.gz"}]}
134134
{"info": {"classifiers": ["Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.9", "Topic :: Software Development :: Libraries :: Python Modules", "Typing :: Typed"], "name": "openai-agents", "requires_python": ">=3.9", "version": "0.2.11", "yanked": false}, "urls": [{"packagetype": "bdist_wheel", "filename": "openai_agents-0.2.11-py3-none-any.whl"}, {"packagetype": "sdist", "filename": "openai_agents-0.2.11.tar.gz"}]}
135135
{"info": {"classifiers": ["Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.9", "Topic :: Software Development :: Libraries :: Python Modules", "Typing :: Typed"], "name": "openai-agents", "requires_python": ">=3.9", "version": "0.4.2", "yanked": false}, "urls": [{"packagetype": "bdist_wheel", "filename": "openai_agents-0.4.2-py3-none-any.whl"}, {"packagetype": "sdist", "filename": "openai_agents-0.4.2.tar.gz"}]}
136-
{"info": {"classifiers": ["Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", "Programming Language :: Python :: 3.9", "Topic :: Software Development :: Libraries :: Python Modules", "Typing :: Typed"], "name": "openai-agents", "requires_python": ">=3.9", "version": "0.5.1", "yanked": false}, "urls": [{"packagetype": "bdist_wheel", "filename": "openai_agents-0.5.1-py3-none-any.whl"}, {"packagetype": "sdist", "filename": "openai_agents-0.5.1.tar.gz"}]}
136+
{"info": {"classifiers": ["Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", "Programming Language :: Python :: 3.9", "Topic :: Software Development :: Libraries :: Python Modules", "Typing :: Typed"], "name": "openai-agents", "requires_python": ">=3.9", "version": "0.6.1", "yanked": false}, "urls": [{"packagetype": "bdist_wheel", "filename": "openai_agents-0.6.1-py3-none-any.whl"}, {"packagetype": "sdist", "filename": "openai_agents-0.6.1.tar.gz"}]}
137137
{"info": {"classifiers": ["License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3"], "name": "openfeature-sdk", "requires_python": ">=3.8", "version": "0.7.5", "yanked": false}, "urls": [{"packagetype": "bdist_wheel", "filename": "openfeature_sdk-0.7.5-py3-none-any.whl"}, {"packagetype": "sdist", "filename": "openfeature_sdk-0.7.5.tar.gz"}]}
138138
{"info": {"classifiers": ["License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3"], "name": "openfeature-sdk", "requires_python": ">=3.9", "version": "0.8.3", "yanked": false}, "urls": [{"packagetype": "bdist_wheel", "filename": "openfeature_sdk-0.8.3-py3-none-any.whl"}, {"packagetype": "sdist", "filename": "openfeature_sdk-0.8.3.tar.gz"}]}
139139
{"info": {"classifiers": ["Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "License :: OSI Approved :: MIT License", "Operating System :: MacOS", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX :: Linux", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", "Programming Language :: Python :: 3.15", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Rust", "Typing :: Typed"], "name": "orjson", "requires_python": ">=3.9", "version": "3.11.4", "yanked": false}, "urls": [{"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp310-cp310-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp310-cp310-musllinux_1_2_aarch64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp310-cp310-musllinux_1_2_armv7l.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp310-cp310-musllinux_1_2_i686.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp310-cp310-musllinux_1_2_x86_64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp310-cp310-win32.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp310-cp310-win_amd64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-macosx_15_0_arm64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-musllinux_1_2_aarch64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-musllinux_1_2_armv7l.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-musllinux_1_2_i686.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-musllinux_1_2_x86_64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-win32.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-win_amd64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp311-cp311-win_arm64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-macosx_15_0_arm64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-musllinux_1_2_aarch64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-musllinux_1_2_armv7l.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-musllinux_1_2_i686.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-musllinux_1_2_x86_64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-win32.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-win_amd64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp312-cp312-win_arm64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-macosx_15_0_arm64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-musllinux_1_2_aarch64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-musllinux_1_2_armv7l.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-musllinux_1_2_i686.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-musllinux_1_2_x86_64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-win32.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-win_amd64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp313-cp313-win_arm64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-macosx_15_0_arm64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-manylinux_2_17_armv7l.manylinux2014_armv7l.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-manylinux_2_17_i686.manylinux2014_i686.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-manylinux_2_17_s390x.manylinux2014_s390x.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-musllinux_1_2_aarch64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-musllinux_1_2_armv7l.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-musllinux_1_2_i686.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-musllinux_1_2_x86_64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-win32.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-win_amd64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp314-cp314-win_arm64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp39-cp39-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp39-cp39-musllinux_1_2_aarch64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp39-cp39-musllinux_1_2_armv7l.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp39-cp39-musllinux_1_2_i686.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp39-cp39-musllinux_1_2_x86_64.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp39-cp39-win32.whl"}, {"packagetype": "bdist_wheel", "filename": "orjson-3.11.4-cp39-cp39-win_amd64.whl"}, {"packagetype": "sdist", "filename": "orjson-3.11.4.tar.gz"}]}

tests/integrations/openai_agents/test_openai_agents.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,6 @@ async def test_handoff_span(sentry_init, capture_events, mock_usage):
294294
name="transfer_to_secondary_agent",
295295
type="function_call",
296296
arguments="{}",
297-
function=MagicMock(
298-
name="transfer_to_secondary_agent", arguments="{}"
299-
),
300297
)
301298
],
302299
usage=mock_usage,
@@ -377,9 +374,6 @@ def simple_test_tool(message: str) -> str:
377374
name="simple_test_tool",
378375
type="function_call",
379376
arguments='{"message": "hello"}',
380-
function=MagicMock(
381-
name="simple_test_tool", arguments='{"message": "hello"}'
382-
),
383377
)
384378

385379
# First response with tool call
@@ -507,11 +501,7 @@ def simple_test_tool(message: str) -> str:
507501
assert ai_client_span1["data"]["gen_ai.usage.output_tokens"] == 5
508502
assert ai_client_span1["data"]["gen_ai.usage.output_tokens.reasoning"] == 0
509503
assert ai_client_span1["data"]["gen_ai.usage.total_tokens"] == 15
510-
assert re.sub(
511-
r"SerializationIterator\(.*\)",
512-
"NOT_CHECKED",
513-
ai_client_span1["data"]["gen_ai.response.tool_calls"],
514-
) == safe_serialize(
504+
assert ai_client_span1["data"]["gen_ai.response.tool_calls"] == safe_serialize(
515505
[
516506
{
517507
"arguments": '{"message": "hello"}',
@@ -520,7 +510,6 @@ def simple_test_tool(message: str) -> str:
520510
"type": "function_call",
521511
"id": "call_123",
522512
"status": None,
523-
"function": "NOT_CHECKED",
524513
}
525514
]
526515
)
@@ -559,11 +548,7 @@ def simple_test_tool(message: str) -> str:
559548
== available_tools
560549
)
561550
assert ai_client_span2["data"]["gen_ai.request.max_tokens"] == 100
562-
assert re.sub(
563-
r"SerializationIterator\(.*\)",
564-
"NOT_CHECKED",
565-
ai_client_span2["data"]["gen_ai.request.messages"],
566-
) == safe_serialize(
551+
assert ai_client_span2["data"]["gen_ai.request.messages"] == safe_serialize(
567552
[
568553
{
569554
"role": "system",
@@ -586,7 +571,6 @@ def simple_test_tool(message: str) -> str:
586571
"name": "simple_test_tool",
587572
"type": "function_call",
588573
"id": "call_123",
589-
"function": "NOT_CHECKED",
590574
}
591575
],
592576
},
@@ -1165,9 +1149,6 @@ def failing_tool(message: str) -> str:
11651149
name="failing_tool",
11661150
type="function_call",
11671151
arguments='{"message": "test"}',
1168-
function=MagicMock(
1169-
name="failing_tool", arguments='{"message": "test"}'
1170-
),
11711152
)
11721153

11731154
# First response with tool call

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ envlist =
109109
{py3.10,py3.11,py3.12}-openai_agents-v0.0.19
110110
{py3.10,py3.12,py3.13}-openai_agents-v0.2.11
111111
{py3.10,py3.12,py3.13}-openai_agents-v0.4.2
112-
{py3.10,py3.13,py3.14,py3.14t}-openai_agents-v0.5.1
112+
{py3.10,py3.13,py3.14,py3.14t}-openai_agents-v0.6.1
113113

114114
{py3.10,py3.12,py3.13}-pydantic_ai-v1.0.18
115115
{py3.10,py3.12,py3.13}-pydantic_ai-v1.7.0
@@ -453,7 +453,7 @@ deps =
453453
openai_agents-v0.0.19: openai-agents==0.0.19
454454
openai_agents-v0.2.11: openai-agents==0.2.11
455455
openai_agents-v0.4.2: openai-agents==0.4.2
456-
openai_agents-v0.5.1: openai-agents==0.5.1
456+
openai_agents-v0.6.1: openai-agents==0.6.1
457457
openai_agents: pytest-asyncio
458458

459459
pydantic_ai-v1.0.18: pydantic-ai==1.0.18

0 commit comments

Comments
 (0)