Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Fix: test router

Sameer Kankute3af994a32a5a
diff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.py
index 6279e96305f..ff9fe6b738a 100644
--- a/tests/test_litellm/test_router.py
+++ b/tests/test_litellm/test_router.py
@@ -1231,18 +1231,30 @@ async def test_acompletion_streaming_disable_fallbacks_midstream():
return self
async def __anext__(self):
- if self.index >= len(self.items):
- raise StopAsyncIteration
if self.index == self.error_after_index:
raise self.error
+ if self.index >= len(self.items):
+ raise StopAsyncIteration
item = self.items[self.index]
self.index += 1
self.chunks.append(item)
return item
- mock_chunks = [
- MagicMock(choices=[MagicMock(delta=MagicMock(content="Hello"))]),
- ]
+ # Create properly structured mock chunks using ModelResponse
+ from litellm.types.utils import Delta, ModelResponse, StreamingChoices
+
+ mock_chunk = ModelResponse(
+ id="chatcmpl-123",
+ choices=[
+ StreamingChoices(
+ index=0, delta=Delta(content="Hello", role="assistant"), finish_reason=None
+ )
+ ],
+ created=1234567890,
+ model="gpt-4",
+ object="chat.completion.chunk",
+ )
+ mock_chunks = [mock_chunk]
mock_error_response = AsyncIteratorWithError(
mock_chunks, 1, error_with_original