Skip to content

Commit 60dad8a

Browse files
committed
address test comments
1 parent 5a12246 commit 60dad8a

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

tests/strands/tools/test_decorator.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,40 +1983,38 @@ def my_tool(name: str, tag: str | None = None) -> str:
19831983
@pytest.mark.asyncio
19841984
async def test_tool_result_event_carries_exception_runtime_error(alist):
19851985
"""Test that ToolResultEvent carries exception when tool raises RuntimeError."""
1986+
exception = RuntimeError("test runtime error")
19861987

19871988
@strands.tool
19881989
def error_tool():
19891990
"""Tool that raises a RuntimeError."""
1990-
raise RuntimeError("test runtime error")
1991+
raise exception
19911992

19921993
tool_use = {"toolUseId": "test-id", "input": {}}
19931994
events = await alist(error_tool.stream(tool_use, {}))
19941995

19951996
result_event = events[-1]
19961997
assert isinstance(result_event, ToolResultEvent)
1997-
assert hasattr(result_event, "exception")
1998-
assert isinstance(result_event.exception, RuntimeError)
1999-
assert str(result_event.exception) == "test runtime error"
1998+
assert result_event.exception is exception
20001999
assert result_event.tool_result["status"] == "error"
20012000

20022001

20032002
@pytest.mark.asyncio
20042003
async def test_tool_result_event_carries_exception_value_error(alist):
20052004
"""Test that ToolResultEvent carries exception when tool raises ValueError."""
2005+
exception = ValueError("validation failed")
20062006

20072007
@strands.tool
20082008
def validation_error_tool():
20092009
"""Tool that raises a ValueError."""
2010-
raise ValueError("validation failed")
2010+
raise exception
20112011

20122012
tool_use = {"toolUseId": "test-id", "input": {}}
20132013
events = await alist(validation_error_tool.stream(tool_use, {}))
20142014

20152015
result_event = events[-1]
20162016
assert isinstance(result_event, ToolResultEvent)
2017-
assert hasattr(result_event, "exception")
2018-
assert isinstance(result_event.exception, ValueError)
2019-
assert str(result_event.exception) == "validation failed"
2017+
assert result_event.exception is exception
20202018
assert result_event.tool_result["status"] == "error"
20212019

20222020

@@ -2041,17 +2039,17 @@ def success_tool():
20412039
@pytest.mark.asyncio
20422040
async def test_tool_result_event_carries_exception_assertion_error(alist):
20432041
"""Test that ToolResultEvent carries AssertionError for unexpected failures."""
2042+
exception = AssertionError("unexpected assertion failure")
20442043

20452044
@strands.tool
20462045
def assertion_error_tool():
20472046
"""Tool that raises an AssertionError."""
2048-
raise AssertionError("unexpected assertion failure")
2047+
raise exception
20492048

20502049
tool_use = {"toolUseId": "test-id", "input": {}}
20512050
events = await alist(assertion_error_tool.stream(tool_use, {}))
20522051

20532052
result_event = events[-1]
20542053
assert isinstance(result_event, ToolResultEvent)
2055-
assert isinstance(result_event.exception, AssertionError)
2056-
assert "unexpected assertion failure" in str(result_event.exception)
2054+
assert result_event.exception is exception
20572055
assert result_event.tool_result["status"] == "error"

0 commit comments

Comments
 (0)