Skip to content

Suppress terminal logging in CI tests #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ def test_agent_description_gets_correctly_inserted_in_system_prompt(self):
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")
Expand Down Expand Up @@ -655,6 +656,11 @@ def get_weather(location: str, celsius: bool = False) -> str:


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)
Expand Down