Skip to content

Commit f3774df

Browse files
committed
✨ Unit test: optimize the display effect of the final answer
1 parent ebf2504 commit f3774df

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

test/sdk/core/agents/test_core_agent.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ def test_step_stream_parse_success(core_agent_instance):
598598

599599

600600
def test_step_stream_skips_execution_for_display_only(core_agent_instance):
601-
"""Test that _step_stream skips execution when only DISPLAY code blocks are present."""
601+
"""Test that _step_stream raises FinalAnswerError when only DISPLAY code blocks are present."""
602602
# Setup
603603
mock_memory_step = MagicMock()
604604
mock_chat_message = MagicMock()
@@ -618,18 +618,16 @@ def test_step_stream_skips_execution_for_display_only(core_agent_instance):
618618
core_agent_instance.write_memory_to_messages = MagicMock(return_value=[])
619619
core_agent_instance.model = MagicMock(return_value=mock_chat_message)
620620

621-
# Execute
622-
results = list(core_agent_instance._step_stream(mock_memory_step))
621+
# Execute and assert that FinalAnswerError is raised
622+
with pytest.raises(core_agent_module.FinalAnswerError):
623+
list(core_agent_instance._step_stream(mock_memory_step))
623624

624-
# Assertions
625-
# Should yield None and return early (not execute code)
626-
assert len(results) == 1
627-
assert results[0] is None
628-
# Verify observation was set
625+
# Verify observation was set before the exception
629626
assert "Display code was provided" in mock_memory_step.observations
630627
assert mock_memory_step.action_output is None
631628
# Verify that tool_calls was NOT set (execution was skipped)
632-
assert not hasattr(mock_memory_step, 'tool_calls') or mock_memory_step.tool_calls is None
629+
# Check if tool_calls was explicitly set by checking __dict__ (MagicMock auto-creates attributes on access)
630+
assert 'tool_calls' not in mock_memory_step.__dict__ or mock_memory_step.tool_calls is None
633631

634632

635633
def test_step_stream_parse_failure_raises_final_answer_error(core_agent_instance):

0 commit comments

Comments
 (0)