diff --git a/litellm/tests/test_exceptions.py b/litellm/tests/test_exceptions.py index 1800cbc5ee..d4a73c8670 100644 --- a/litellm/tests/test_exceptions.py +++ b/litellm/tests/test_exceptions.py @@ -455,15 +455,21 @@ def test_completion_perplexity_exception_on_openai_client(): # delete perplexityai api key to simulate bad api key del os.environ["PERPLEXITYAI_API_KEY"] + + # temporaily delete openai api key + original_openai_key = os.environ["OPENAI_API_KEY"] del os.environ["OPENAI_API_KEY"] + response = completion( model="perplexity/mistral-7b-instruct", messages=[{"role": "user", "content": "hello"}], ) os.environ["PERPLEXITYAI_API_KEY"] = old_azure_key + os.environ["OPENAI_API_KEY"] = original_openai_key pytest.fail("Request should have failed - bad api key") except openai.AuthenticationError as e: os.environ["PERPLEXITYAI_API_KEY"] = old_azure_key + os.environ["OPENAI_API_KEY"] = original_openai_key print("exception: ", e) assert ( "perplexity.perplexityError: The api_key client option must be set either by passing api_key to the client or by setting the PERPLEXITY_API_KEY environment variable"