feat: add fixed time to fix test

This commit is contained in:
Eduardo Chiarotti
2025-02-10 11:24:07 -03:00
parent c20020e3fb
commit bd6e45b905

View File

@@ -1,6 +1,7 @@
"""Test Agent creation and execution basic functionality."""
import os
from datetime import UTC, datetime, timezone
from unittest import mock
from unittest.mock import patch
@@ -908,6 +909,8 @@ def test_tool_result_as_answer_is_the_final_answer_for_the_agent():
@pytest.mark.vcr(filter_headers=["authorization"])
def test_tool_usage_information_is_appended_to_agent():
from datetime import UTC, datetime
from crewai.tools import BaseTool
class MyCustomTool(BaseTool):
@@ -917,6 +920,11 @@ def test_tool_usage_information_is_appended_to_agent():
def _run(self) -> str:
return "Howdy!"
fixed_datetime = datetime(2025, 2, 10, 12, 0, 0, tzinfo=UTC)
with patch("crewai.tools.tool_usage.datetime") as mock_datetime:
mock_datetime.now.return_value = fixed_datetime
mock_datetime.UTC = UTC
agent1 = Agent(
role="Friendly Neighbor",
goal="Make everyone feel welcome",
@@ -939,6 +947,7 @@ def test_tool_usage_information_is_appended_to_agent():
"tool_name": "Decide Greetings",
"tool_args": {},
"result_as_answer": True,
"start_time": fixed_datetime,
}
]