@@ -965,6 +965,45 @@ def test_step_stream_execution_error_without_print_outputs(core_agent_instance):
965965 list (core_agent_instance ._step_stream (mock_memory_step ))
966966
967967
968+ def test_step_stream_execution_with_none_output (core_agent_instance ):
969+ """Test _step_stream method when execution returns None output."""
970+ # Setup
971+ mock_memory_step = MagicMock ()
972+ mock_chat_message = MagicMock ()
973+ mock_chat_message .content = "```<RUN>\n print('hello')\n ```<END_CODE>"
974+
975+ # Set all required attributes on the instance
976+ core_agent_instance .agent_name = "test_agent"
977+ core_agent_instance .step_number = 1
978+ core_agent_instance .grammar = None
979+ core_agent_instance .logger = MagicMock ()
980+ core_agent_instance .memory = MagicMock ()
981+ core_agent_instance .memory .steps = []
982+
983+ with patch .object (core_agent_module , 'parse_code_blobs' , return_value = "print('hello')" ), \
984+ patch .object (core_agent_module , 'fix_final_answer_code' , return_value = "print('hello')" ):
985+
986+ # Mock the methods directly on the instance
987+ core_agent_instance .write_memory_to_messages = MagicMock (
988+ return_value = [])
989+ core_agent_instance .model = MagicMock (return_value = mock_chat_message )
990+ # Mock python_executor to return None output
991+ core_agent_instance .python_executor = MagicMock (
992+ return_value = (None , "Execution logs" , False ))
993+
994+ # Execute
995+ result = list (core_agent_instance ._step_stream (mock_memory_step ))
996+
997+ # Assertions
998+ # Should yield None when is_final_answer is False
999+ assert result [0 ] is None
1000+ assert mock_memory_step .observations is not None
1001+ # Check that observations was set but should not contain "Last output from code snippet"
1002+ # since output is None
1003+ observations_str = str (mock_memory_step .observations )
1004+ assert "Execution logs:" in observations_str
1005+ assert "Last output from code snippet:" not in observations_str
1006+
9681007# ----------------------------------------------------------------------------
9691008# Tests for run method (lines 229-263)
9701009# ----------------------------------------------------------------------------
0 commit comments