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:
		
							parent
							
								
									66b76200e7
								
							
						
					
					
						commit
						ce5ede8c12
					
				|  | @ -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 | ||||||
|  | @ -481,7 +481,8 @@ class AgentTests(unittest.TestCase): | ||||||
|         assert "You can also give requests to team members." in manager_agent.system_prompt |         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): |     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: |         with agent.logger.console.capture() as capture: | ||||||
|             agent.run("Count to 3") |             agent.run("Count to 3") | ||||||
|  | @ -655,6 +656,11 @@ nested_answer() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class TestMultiStepAgent: | 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): |     def test_step_number(self): | ||||||
|         fake_model = MagicMock() |         fake_model = MagicMock() | ||||||
|         agent = MultiStepAgent(tools=[], model=fake_model) |         agent = MultiStepAgent(tools=[], model=fake_model) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue