mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
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:
parent
3fd556c75f
commit
899038a2ce
1 changed files with 3 additions and 1 deletions
|
|
@ -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"}],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue