diff --git a/pyproject.toml b/pyproject.toml index 1c4e751c1..44fb6db9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,6 +90,18 @@ dev-dependencies = [ "pytest-timeout>=2.3.1", ] +[tool.pytest.ini_options] +filterwarnings = [ + # Suppress Pydantic field conflict warnings from StagehandTool in crewai_tools + "ignore:Field \"model_api_key\" in StagehandTool has conflict with protected namespace \"model_\".:UserWarning", + "ignore:Field \"model_name\" in StagehandTool has conflict with protected namespace \"model_\".:UserWarning", + # Suppress Pydantic V2 deprecation warning for json_encoders + "ignore:`json_encoders` is deprecated.*:pydantic.warnings.PydanticDeprecatedSince20", + # Suppress pytest-asyncio configuration warning + "ignore:The configuration option \"asyncio_default_fixture_loop_scope\" is unset.*:pytest.PytestDeprecationWarning", +] +asyncio_default_fixture_loop_scope = "function" + [project.scripts] crewai = "crewai.cli.cli:crewai" diff --git a/tests/test_agent_inject_date.py b/tests/test_agent_inject_date.py index b37559aca..5516da730 100644 --- a/tests/test_agent_inject_date.py +++ b/tests/test_agent_inject_date.py @@ -7,67 +7,70 @@ from crewai.task import Task def test_agent_inject_date(): """Test that the inject_date flag injects the current date into the task. - + Tests that when inject_date=True, the current date is added to the task description. """ with patch('datetime.datetime') as mock_datetime: mock_datetime.now.return_value = datetime(2025, 1, 1) - + agent = Agent( role="test_agent", goal="test_goal", backstory="test_backstory", inject_date=True, ) - + task = Task( description="Test task", expected_output="Test output", agent=agent, ) - + # Store original description original_description = task.description - + agent._inject_date_to_task(task) - + assert "Current Date: 2025-01-01" in task.description assert task.description != original_description def test_agent_without_inject_date(): - """Test that without inject_date flag, no date is injected. - - Tests that when inject_date=False (default), no date is added to the task description. """ + Tests that when inject_date=True (default). + """ + with patch('datetime.datetime') as mock_datetime: + mock_datetime.now.return_value = datetime(2025, 1, 1) + agent = Agent( role="test_agent", goal="test_goal", backstory="test_backstory", - # inject_date is False by default + # inject_date is True by default ) - + task = Task( description="Test task", expected_output="Test output", agent=agent, ) - + original_description = task.description - + agent._inject_date_to_task(task) - - assert task.description == original_description + + assert "Current Date: 2025-01-01" in task.description + assert task.description != original_description def test_agent_inject_date_custom_format(): """Test that the inject_date flag with custom date_format works correctly. - + Tests that when inject_date=True with a custom date_format, the date is formatted correctly. """ with patch('datetime.datetime') as mock_datetime: mock_datetime.now.return_value = datetime(2025, 1, 1) - + agent = Agent( role="test_agent", goal="test_goal", @@ -75,25 +78,25 @@ def test_agent_inject_date_custom_format(): inject_date=True, date_format="%d/%m/%Y", ) - + task = Task( description="Test task", expected_output="Test output", agent=agent, ) - + # Store original description original_description = task.description - + agent._inject_date_to_task(task) - + assert "Current Date: 01/01/2025" in task.description assert task.description != original_description def test_agent_inject_date_invalid_format(): """Test error handling with invalid date format. - + Tests that when an invalid date_format is provided, the task description remains unchanged. """ agent = Agent( @@ -103,15 +106,15 @@ def test_agent_inject_date_invalid_format(): inject_date=True, date_format="invalid", ) - + task = Task( description="Test task", expected_output="Test output", agent=agent, ) - + original_description = task.description - + agent._inject_date_to_task(task) - + assert task.description == original_description