@@ -100,9 +100,11 @@ def test_call_llm_timeout_retry(self, mock_llm):
100100 Mock (content = "Success after retry" ),
101101 ]
102102
103- with patch ("agent_pipeline.llms.client.get_llm" , return_value = mock_llm ):
104- with patch ("time.sleep" ): # Skip actual sleep in tests
105- response = call_llm ("System prompt" , "User prompt" , max_retries = 2 )
103+ with (
104+ patch ("agent_pipeline.llms.client.get_llm" , return_value = mock_llm ),
105+ patch ("time.sleep" ), # Skip actual sleep in tests
106+ ):
107+ response = call_llm ("System prompt" , "User prompt" , max_retries = 2 )
106108
107109 assert response == "Success after retry"
108110 assert mock_llm .invoke .call_count == 2
@@ -111,42 +113,50 @@ def test_call_llm_timeout_exhausted(self, mock_llm):
111113 """Test LLM call when all retries are exhausted."""
112114 mock_llm .invoke .side_effect = Exception ("Read timed out" )
113115
114- with patch ("agent_pipeline.llms.client.get_llm" , return_value = mock_llm ):
115- with patch ("time.sleep" ): # Skip actual sleep in tests
116- with pytest .raises (TimeoutError , match = "failed to respond after .* attempts" ):
117- call_llm ("System prompt" , "User prompt" , max_retries = 2 )
116+ with (
117+ patch ("agent_pipeline.llms.client.get_llm" , return_value = mock_llm ),
118+ patch ("time.sleep" ), # Skip actual sleep in tests
119+ pytest .raises (TimeoutError , match = "failed to respond after .* attempts" ),
120+ ):
121+ call_llm ("System prompt" , "User prompt" , max_retries = 2 )
118122
119123 assert mock_llm .invoke .call_count == 2
120124
121125 def test_call_llm_non_timeout_error (self , mock_llm ):
122126 """Test LLM call with non-timeout error (should not retry)."""
123127 mock_llm .invoke .side_effect = ValueError ("Invalid input" )
124128
125- with patch ("agent_pipeline.llms.client.get_llm" , return_value = mock_llm ):
126- with pytest .raises (ValueError , match = "Invalid input" ):
127- call_llm ("System prompt" , "User prompt" , max_retries = 3 )
129+ with (
130+ patch ("agent_pipeline.llms.client.get_llm" , return_value = mock_llm ),
131+ pytest .raises (ValueError , match = "Invalid input" ),
132+ ):
133+ call_llm ("System prompt" , "User prompt" , max_retries = 3 )
128134
129135 assert mock_llm .invoke .call_count == 1 # Should not retry
130136
131137 def test_call_llm_custom_retries (self , mock_llm ):
132138 """Test LLM call with custom retry count."""
133139 mock_llm .invoke .side_effect = Exception ("timeout" )
134140
135- with patch ("agent_pipeline.llms.client.get_llm" , return_value = mock_llm ):
136- with patch ("time.sleep" ):
137- with pytest .raises (TimeoutError ):
138- call_llm ("System prompt" , "User prompt" , max_retries = 5 )
141+ with (
142+ patch ("agent_pipeline.llms.client.get_llm" , return_value = mock_llm ),
143+ patch ("time.sleep" ),
144+ pytest .raises (TimeoutError ),
145+ ):
146+ call_llm ("System prompt" , "User prompt" , max_retries = 5 )
139147
140148 assert mock_llm .invoke .call_count == 5
141149
142150 def test_call_llm_default_retries (self , mock_llm ):
143151 """Test LLM call uses default retry count from config."""
144152 mock_llm .invoke .side_effect = Exception ("timeout" )
145153
146- with patch ("agent_pipeline.llms.client.get_llm" , return_value = mock_llm ):
147- with patch ("time.sleep" ):
148- with pytest .raises (TimeoutError ):
149- call_llm ("System prompt" , "User prompt" ) # No max_retries specified
154+ with (
155+ patch ("agent_pipeline.llms.client.get_llm" , return_value = mock_llm ),
156+ patch ("time.sleep" ),
157+ pytest .raises (TimeoutError ),
158+ ):
159+ call_llm ("System prompt" , "User prompt" ) # No max_retries specified
150160
151161 assert mock_llm .invoke .call_count == LLM_MAX_RETRIES
152162
@@ -235,9 +245,11 @@ def test_call_llm_retry_timing(self, mock_llm):
235245 # First call fails, second succeeds
236246 mock_llm .invoke .side_effect = [Exception ("timeout" ), Mock (content = "Success" )]
237247
238- with patch ("agent_pipeline.llms.client.get_llm" , return_value = mock_llm ):
239- with patch ("time.sleep" ) as mock_sleep :
240- call_llm ("System" , "User" , max_retries = 2 )
248+ with (
249+ patch ("agent_pipeline.llms.client.get_llm" , return_value = mock_llm ),
250+ patch ("time.sleep" ) as mock_sleep ,
251+ ):
252+ call_llm ("System" , "User" , max_retries = 2 )
241253
242254 # Should sleep between retries
243255 mock_sleep .assert_called_once_with (5 )
0 commit comments