fix(tests): fix repeating chunk and audio usage streaming tests (#23061)

- Replace ModelResponse(stream=True) with ModelResponseStream in
  test_unit_test_custom_stream_wrapper_repeating_chunk — stream=True
  stores delta as a plain dict causing AttributeError in CustomStreamWrapper
- Accept MidStreamFallbackError alongside InternalServerError in the
  repeating-chunk safety check assertion
- Add @pytest.mark.flaky(retries=3) to the live OpenAI audio output
  usage test
This commit is contained in:
Ishaan Jaff 2026-03-07 16:18:51 -08:00 committed by GitHub
parent a50a84c16c
commit e8a7116899
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 17 deletions

View File

@ -636,6 +636,7 @@ def test_stream_chunk_builder_openai_prompt_caching():
assert response_usage_value == v
@pytest.mark.flaky(retries=3, delay=2)
def test_stream_chunk_builder_openai_audio_output_usage():
from pydantic import BaseModel
from openai import OpenAI

View File

@ -3075,22 +3075,18 @@ def test_unit_test_custom_stream_wrapper_repeating_chunk(
"""
litellm.set_verbose = False
chunks = [
litellm.ModelResponse(
**{
"id": "chatcmpl-123",
"object": "chat.completion.chunk",
"created": 1694268190,
"model": "gpt-3.5-turbo-0125",
"system_fingerprint": "fp_44709d6fcb",
"choices": [
{
"index": 0,
"delta": {"content": chunk_value},
"finish_reason": "stop",
}
],
},
stream=True,
litellm.ModelResponseStream(
id="chatcmpl-123",
created=1694268190,
model="gpt-3.5-turbo-0125",
system_fingerprint="fp_44709d6fcb",
choices=[
{
"index": 0,
"delta": {"content": chunk_value},
"finish_reason": "stop",
}
],
)
] * loop_amount
completion_stream = ModelResponseListIterator(model_responses=chunks)
@ -3113,7 +3109,7 @@ def test_unit_test_custom_stream_wrapper_repeating_chunk(
print(f"expected_chunk_fail: {expected_chunk_fail}")
if (loop_amount > litellm.REPEATED_STREAMING_CHUNK_LIMIT) and expected_chunk_fail:
with pytest.raises(litellm.InternalServerError):
with pytest.raises((litellm.InternalServerError, litellm.exceptions.MidStreamFallbackError)):
for chunk in response:
continue
else: