Skip to content

Commit ce5ede8

Browse files
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
1 parent 66b7620 commit ce5ede8

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from unittest.mock import patch
2+
3+
import pytest
4+
5+
from smolagents.agents import MultiStepAgent
6+
7+
8+
original_multi_step_agent_init = MultiStepAgent.__init__
9+
10+
11+
@pytest.fixture(autouse=True)
12+
def patch_multi_step_agent_with_suppressed_logging():
13+
with patch.object(MultiStepAgent, "__init__", autospec=True) as mock_init:
14+
15+
def init_with_suppressed_logging(self, *args, verbosity_level=-1, **kwargs):
16+
original_multi_step_agent_init(self, *args, verbosity_level=verbosity_level, **kwargs)
17+
18+
mock_init.side_effect = init_with_suppressed_logging
19+
yield

tests/test_agents.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ def test_agent_description_gets_correctly_inserted_in_system_prompt(self):
481481
assert "You can also give requests to team members." in manager_agent.system_prompt
482482

483483
def test_code_agent_missing_import_triggers_advice_in_error_log(self):
484-
agent = CodeAgent(tools=[], model=fake_code_model_import)
484+
# Set explicit verbosity level to 1 to override the default verbosity level of -1 set in CI fixture
485+
agent = CodeAgent(tools=[], model=fake_code_model_import, verbosity_level=1)
485486

486487
with agent.logger.console.capture() as capture:
487488
agent.run("Count to 3")
@@ -655,6 +656,11 @@ def get_weather(location: str, celsius: bool = False) -> str:
655656

656657

657658
class TestMultiStepAgent:
659+
def test_logging_to_terminal_is_disabled(self):
660+
fake_model = MagicMock()
661+
agent = MultiStepAgent(tools=[], model=fake_model)
662+
assert agent.logger.level == -1, "logging to terminal should be disabled for testing using a fixture"
663+
658664
def test_step_number(self):
659665
fake_model = MagicMock()
660666
agent = MultiStepAgent(tools=[], model=fake_model)

0 commit comments

Comments
 (0)