From 09240a7b62eb557085c1d2a4e42a2ef4aea77749 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sun, 9 Feb 2025 22:59:56 +0000 Subject: [PATCH] fix: remove duplicate assertions in test_crew_testing_function Co-Authored-By: Joe Moura --- tests/crew_test.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/crew_test.py b/tests/crew_test.py index e69c71315..0b8589550 100644 --- a/tests/crew_test.py +++ b/tests/crew_test.py @@ -3306,8 +3306,7 @@ def test_conditional_should_execute(): @mock.patch("crewai.crew.CrewEvaluator") @mock.patch("crewai.crew.Crew.copy") -@mock.patch("crewai.crew.Crew.kickoff") -def test_crew_testing_function(kickoff_mock, copy_mock, crew_evaluator): +def test_crew_testing_function(copy_mock, crew_evaluator_mock): task = Task( description="Come up with a list of 5 interesting ideas to explore for an article, then write one amazing paragraph highlight for each idea that showcases how good an article about this topic could be. Return the list of ideas with their paragraph and your notes.", expected_output="5 bullet points with a paragraph for each idea.", @@ -3319,18 +3318,24 @@ def test_crew_testing_function(kickoff_mock, copy_mock, crew_evaluator): tasks=[task], ) - # Create a mock for the copied crew - copy_mock.return_value = crew + # Create a mock for the copied crew with a mock kickoff method + copied_crew = MagicMock() + copy_mock.return_value = copied_crew + + # Create a mock for the CrewEvaluator instance + evaluator_instance = MagicMock() + crew_evaluator_mock.return_value = evaluator_instance n_iterations = 2 crew.test(n_iterations, openai_model_name="gpt-4o-mini", inputs={"topic": "AI"}) # Ensure kickoff is called on the copied crew - kickoff_mock.assert_has_calls( + copied_crew.kickoff.assert_has_calls( [mock.call(inputs={"topic": "AI"}), mock.call(inputs={"topic": "AI"})] ) - crew_evaluator.assert_has_calls( + # Verify CrewEvaluator interactions + crew_evaluator_mock.assert_has_calls( [ mock.call(crew, "gpt-4o-mini"), mock.call().set_iteration(1), @@ -3338,6 +3343,10 @@ def test_crew_testing_function(kickoff_mock, copy_mock, crew_evaluator): mock.call().print_crew_evaluation_result(), ] ) + mock.call().set_iteration(2), + mock.call().print_crew_evaluation_result(), + ] + ) @pytest.mark.vcr(filter_headers=["authorization"])