From ce4f36bd4d8e5b15792761dd61cb54491cc6a7fe Mon Sep 17 00:00:00 2001 From: Lucas Gomide Date: Wed, 16 Apr 2025 17:45:46 -0300 Subject: [PATCH] refactor: remove @skip_streaming_in_ci Since we have fixed streaming response issue we can remove this @skip_streaming_in_ci --- tests/crew_test.py | 97 +++++++++++++++++++++++----------- tests/utilities/test_events.py | 7 --- 2 files changed, 65 insertions(+), 39 deletions(-) diff --git a/tests/crew_test.py b/tests/crew_test.py index fd0d9f3d4..cb0151f2d 100644 --- a/tests/crew_test.py +++ b/tests/crew_test.py @@ -42,11 +42,6 @@ from crewai.utilities.events.event_listener import EventListener from crewai.utilities.rpm_controller import RPMController from crewai.utilities.task_output_storage_handler import TaskOutputStorageHandler -# Skip streaming tests when running in CI/CD environments -skip_streaming_in_ci = pytest.mark.skipif( - os.getenv("CI") is not None, reason="Skipping streaming tests in CI/CD environments" -) - ceo = Agent( role="CEO", goal="Make sure the writers in your company produce amazing content.", @@ -963,7 +958,6 @@ def test_api_calls_throttling(capsys): moveon.assert_called() -@skip_streaming_in_ci @pytest.mark.vcr(filter_headers=["authorization"]) def test_crew_kickoff_usage_metrics(): inputs = [ @@ -999,7 +993,6 @@ def test_crew_kickoff_usage_metrics(): assert result.token_usage.cached_prompt_tokens == 0 -@skip_streaming_in_ci @pytest.mark.vcr(filter_headers=["authorization"]) def test_crew_kickoff_streaming_usage_metrics(): inputs = [ @@ -4256,53 +4249,93 @@ def test_crew_kickoff_for_each_works_with_manager_agent_copy(): assert crew_copy.manager_agent.role == crew.manager_agent.role assert crew_copy.manager_agent.goal == crew.manager_agent.goal + def test_crew_copy_with_memory(): """Test that copying a crew with memory enabled does not raise validation errors and copies memory correctly.""" agent = Agent(role="Test Agent", goal="Test Goal", backstory="Test Backstory") task = Task(description="Test Task", expected_output="Test Output", agent=agent) crew = Crew(agents=[agent], tasks=[task], memory=True) - original_short_term_id = id(crew._short_term_memory) if crew._short_term_memory else None - original_long_term_id = id(crew._long_term_memory) if crew._long_term_memory else None + original_short_term_id = ( + id(crew._short_term_memory) if crew._short_term_memory else None + ) + original_long_term_id = ( + id(crew._long_term_memory) if crew._long_term_memory else None + ) original_entity_id = id(crew._entity_memory) if crew._entity_memory else None original_external_id = id(crew._external_memory) if crew._external_memory else None original_user_id = id(crew._user_memory) if crew._user_memory else None - try: crew_copy = crew.copy() - assert hasattr(crew_copy, "_short_term_memory"), "Copied crew should have _short_term_memory" - assert crew_copy._short_term_memory is not None, "Copied _short_term_memory should not be None" - assert id(crew_copy._short_term_memory) != original_short_term_id, "Copied _short_term_memory should be a new object" + assert hasattr( + crew_copy, "_short_term_memory" + ), "Copied crew should have _short_term_memory" + assert ( + crew_copy._short_term_memory is not None + ), "Copied _short_term_memory should not be None" + assert ( + id(crew_copy._short_term_memory) != original_short_term_id + ), "Copied _short_term_memory should be a new object" - assert hasattr(crew_copy, "_long_term_memory"), "Copied crew should have _long_term_memory" - assert crew_copy._long_term_memory is not None, "Copied _long_term_memory should not be None" - assert id(crew_copy._long_term_memory) != original_long_term_id, "Copied _long_term_memory should be a new object" + assert hasattr( + crew_copy, "_long_term_memory" + ), "Copied crew should have _long_term_memory" + assert ( + crew_copy._long_term_memory is not None + ), "Copied _long_term_memory should not be None" + assert ( + id(crew_copy._long_term_memory) != original_long_term_id + ), "Copied _long_term_memory should be a new object" - assert hasattr(crew_copy, "_entity_memory"), "Copied crew should have _entity_memory" - assert crew_copy._entity_memory is not None, "Copied _entity_memory should not be None" - assert id(crew_copy._entity_memory) != original_entity_id, "Copied _entity_memory should be a new object" + assert hasattr( + crew_copy, "_entity_memory" + ), "Copied crew should have _entity_memory" + assert ( + crew_copy._entity_memory is not None + ), "Copied _entity_memory should not be None" + assert ( + id(crew_copy._entity_memory) != original_entity_id + ), "Copied _entity_memory should be a new object" if original_external_id: - assert hasattr(crew_copy, "_external_memory"), "Copied crew should have _external_memory" - assert crew_copy._external_memory is not None, "Copied _external_memory should not be None" - assert id(crew_copy._external_memory) != original_external_id, "Copied _external_memory should be a new object" + assert hasattr( + crew_copy, "_external_memory" + ), "Copied crew should have _external_memory" + assert ( + crew_copy._external_memory is not None + ), "Copied _external_memory should not be None" + assert ( + id(crew_copy._external_memory) != original_external_id + ), "Copied _external_memory should be a new object" else: - assert not hasattr(crew_copy, "_external_memory") or crew_copy._external_memory is None, "Copied _external_memory should be None if not originally present" + assert ( + not hasattr(crew_copy, "_external_memory") + or crew_copy._external_memory is None + ), "Copied _external_memory should be None if not originally present" if original_user_id: - assert hasattr(crew_copy, "_user_memory"), "Copied crew should have _user_memory" - assert crew_copy._user_memory is not None, "Copied _user_memory should not be None" - assert id(crew_copy._user_memory) != original_user_id, "Copied _user_memory should be a new object" + assert hasattr( + crew_copy, "_user_memory" + ), "Copied crew should have _user_memory" + assert ( + crew_copy._user_memory is not None + ), "Copied _user_memory should not be None" + assert ( + id(crew_copy._user_memory) != original_user_id + ), "Copied _user_memory should be a new object" else: - assert not hasattr(crew_copy, "_user_memory") or crew_copy._user_memory is None, "Copied _user_memory should be None if not originally present" - + assert ( + not hasattr(crew_copy, "_user_memory") or crew_copy._user_memory is None + ), "Copied _user_memory should be None if not originally present" except pydantic_core.ValidationError as e: - if "Input should be an instance of" in str(e) and ("Memory" in str(e)): - pytest.fail(f"Copying with memory raised Pydantic ValidationError, likely due to incorrect memory copy: {e}") - else: - raise e # Re-raise other validation errors + if "Input should be an instance of" in str(e) and ("Memory" in str(e)): + pytest.fail( + f"Copying with memory raised Pydantic ValidationError, likely due to incorrect memory copy: {e}" + ) + else: + raise e # Re-raise other validation errors except Exception as e: pytest.fail(f"Copying crew raised an unexpected exception: {e}") diff --git a/tests/utilities/test_events.py b/tests/utilities/test_events.py index ae9a39660..150a383cb 100644 --- a/tests/utilities/test_events.py +++ b/tests/utilities/test_events.py @@ -58,11 +58,6 @@ def vcr_config(request) -> dict: } -# Skip streaming tests when running in CI/CD environments -skip_streaming_in_ci = pytest.mark.skipif( - os.getenv("CI") is not None, reason="Skipping streaming tests in CI/CD environments" -) - base_agent = Agent( role="base_agent", llm="gpt-4o-mini", @@ -633,7 +628,6 @@ def test_llm_emits_call_failed_event(): assert received_events[0].error == error_message -@skip_streaming_in_ci @pytest.mark.vcr(filter_headers=["authorization"]) def test_llm_emits_stream_chunk_events(): """Test that LLM emits stream chunk events when streaming is enabled.""" @@ -658,7 +652,6 @@ def test_llm_emits_stream_chunk_events(): assert "".join(received_chunks) == response -@skip_streaming_in_ci @pytest.mark.vcr(filter_headers=["authorization"]) def test_llm_no_stream_chunks_when_streaming_disabled(): """Test that LLM doesn't emit stream chunk events when streaming is disabled."""