fix(tests): narrow perplexity exception catch to openai.OpenAIError

Greptile feedback on #28087: catching bare Exception in pytest.raises
also accepts unrelated KeyError/AttributeError from setup bugs. Narrow
to openai.OpenAIError — the root of the openai SDK exception tree.
Every LiteLLM exception class (AuthenticationError, InternalServerError,
APIError, APIConnectionError, ...) subclasses an openai.* exception, so
this covers both the pre-2.34 path (openai.AuthenticationError raised
at request time) and the 2.34+ path (litellm.InternalServerError
wrapping the construction-time OpenAIError) without admitting unrelated
exceptions.
This commit is contained in:
mateo-berri 2026-05-16 14:16:09 -07:00
parent 3fd556c75f
commit 899038a2ce

View file

@ -581,6 +581,8 @@ def test_content_policy_violation_error_streaming():
def test_completion_perplexity_exception_on_openai_client():
import openai
print("perplexity test\n\n")
litellm.set_verbose = False
old_perplexity_key = os.environ["PERPLEXITYAI_API_KEY"]
@ -588,7 +590,7 @@ def test_completion_perplexity_exception_on_openai_client():
del os.environ["PERPLEXITYAI_API_KEY"]
del os.environ["OPENAI_API_KEY"]
try:
with pytest.raises(Exception) as exc_info:
with pytest.raises(openai.OpenAIError) as exc_info:
completion(
model="perplexity/mistral-7b-instruct",
messages=[{"role": "user", "content": "hello"}],