mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-27 00:58:13 +00:00
fix: Update warning log tests to use custom Logger monkeypatch
The project uses a custom Logger that emits via _logger.log() rather than Python's standard logging module, so caplog won't capture the warnings. Updated tests to monkeypatch agent._logger.log instead of using caplog. Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -161,7 +161,7 @@ class TestHTTPMCPFragmentFiltering:
|
|||||||
class TestHTTPMCPWarningLog:
|
class TestHTTPMCPWarningLog:
|
||||||
"""Test warning log for HTTP MCP URLs."""
|
"""Test warning log for HTTP MCP URLs."""
|
||||||
|
|
||||||
def test_warning_log_emitted_for_http_url(self, caplog):
|
def test_warning_log_emitted_for_http_url(self):
|
||||||
"""Test that warning log is emitted when http:// is used."""
|
"""Test that warning log is emitted when http:// is used."""
|
||||||
agent = Agent(
|
agent = Agent(
|
||||||
role="Test Agent",
|
role="Test Agent",
|
||||||
@@ -170,15 +170,23 @@ class TestHTTPMCPWarningLog:
|
|||||||
verbose=True,
|
verbose=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch.object(agent, '_get_mcp_tool_schemas', return_value={}):
|
log_calls = []
|
||||||
with caplog.at_level("WARNING"):
|
original_log = agent._logger.log
|
||||||
|
|
||||||
|
def mock_log(level, message):
|
||||||
|
log_calls.append((level, message))
|
||||||
|
return original_log(level, message)
|
||||||
|
|
||||||
|
with patch.object(agent._logger, 'log', side_effect=mock_log):
|
||||||
|
with patch.object(agent, '_get_mcp_tool_schemas', return_value={}):
|
||||||
agent._get_external_mcp_tools("http://localhost:7365/mcp")
|
agent._get_external_mcp_tools("http://localhost:7365/mcp")
|
||||||
|
|
||||||
assert any("http://" in record.message for record in caplog.records)
|
warning_messages = [msg for level, msg in log_calls if level == "warning"]
|
||||||
assert any("local development" in record.message for record in caplog.records)
|
assert any("http://" in msg for msg in warning_messages)
|
||||||
assert any("https://" in record.message for record in caplog.records)
|
assert any("local development" in msg for msg in warning_messages)
|
||||||
|
assert any("https://" in msg for msg in warning_messages)
|
||||||
|
|
||||||
def test_no_warning_log_for_https_url(self, caplog):
|
def test_no_warning_log_for_https_url(self):
|
||||||
"""Test that no warning log is emitted for https:// URLs."""
|
"""Test that no warning log is emitted for https:// URLs."""
|
||||||
agent = Agent(
|
agent = Agent(
|
||||||
role="Test Agent",
|
role="Test Agent",
|
||||||
@@ -187,8 +195,16 @@ class TestHTTPMCPWarningLog:
|
|||||||
verbose=True,
|
verbose=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch.object(agent, '_get_mcp_tool_schemas', return_value={}):
|
log_calls = []
|
||||||
with caplog.at_level("WARNING"):
|
original_log = agent._logger.log
|
||||||
|
|
||||||
|
def mock_log(level, message):
|
||||||
|
log_calls.append((level, message))
|
||||||
|
return original_log(level, message)
|
||||||
|
|
||||||
|
with patch.object(agent._logger, 'log', side_effect=mock_log):
|
||||||
|
with patch.object(agent, '_get_mcp_tool_schemas', return_value={}):
|
||||||
agent._get_external_mcp_tools("https://api.example.com/mcp")
|
agent._get_external_mcp_tools("https://api.example.com/mcp")
|
||||||
|
|
||||||
assert not any("http://" in record.message and "local development" in record.message for record in caplog.records)
|
warning_messages = [msg for level, msg in log_calls if level == "warning"]
|
||||||
|
assert not any("http://" in msg and "local development" in msg for msg in warning_messages)
|
||||||
|
|||||||
Reference in New Issue
Block a user