Suppress terminal logging in CI tests (#504)

* Test logging to terminal is disabled for testing

* Suppress terminal logging in CI tests

* Pass verbosity_level to test terminal logging output

* Refactor
This commit is contained in:
Albert Villanova del Moral 2025-02-05 18:48:39 +01:00 committed by GitHub
parent 66b76200e7
commit ce5ede8c12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

19
tests/conftest.py Normal file
View File

@ -0,0 +1,19 @@
from unittest.mock import patch
import pytest
from smolagents.agents import MultiStepAgent
original_multi_step_agent_init = MultiStepAgent.__init__
@pytest.fixture(autouse=True)
def patch_multi_step_agent_with_suppressed_logging():
with patch.object(MultiStepAgent, "__init__", autospec=True) as mock_init:
def init_with_suppressed_logging(self, *args, verbosity_level=-1, **kwargs):
original_multi_step_agent_init(self, *args, verbosity_level=verbosity_level, **kwargs)
mock_init.side_effect = init_with_suppressed_logging
yield

View File

@ -481,7 +481,8 @@ class AgentTests(unittest.TestCase):
assert "You can also give requests to team members." in manager_agent.system_prompt
def test_code_agent_missing_import_triggers_advice_in_error_log(self):
agent = CodeAgent(tools=[], model=fake_code_model_import)
# Set explicit verbosity level to 1 to override the default verbosity level of -1 set in CI fixture
agent = CodeAgent(tools=[], model=fake_code_model_import, verbosity_level=1)
with agent.logger.console.capture() as capture:
agent.run("Count to 3")
@ -655,6 +656,11 @@ nested_answer()
class TestMultiStepAgent:
def test_logging_to_terminal_is_disabled(self):
fake_model = MagicMock()
agent = MultiStepAgent(tools=[], model=fake_model)
assert agent.logger.level == -1, "logging to terminal should be disabled for testing using a fixture"
def test_step_number(self):
fake_model = MagicMock()
agent = MultiStepAgent(tools=[], model=fake_model)