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]

test_azure_common_utils.py

Ishaan Jaff4f98862ef9e9
diff --git a/tests/test_litellm/llms/azure/test_azure_common_utils.py b/tests/test_litellm/llms/azure/test_azure_common_utils.py
index 0ae04c357e7..8c5fd7e5e08 100644
--- a/tests/test_litellm/llms/azure/test_azure_common_utils.py
+++ b/tests/test_litellm/llms/azure/test_azure_common_utils.py
@@ -12,13 +12,22 @@ sys.path.insert(
) # Adds the parent directory to the system path
import litellm
from litellm.llms.azure.common_utils import BaseAzureLLM, get_azure_ad_token
-from litellm.types.utils import CallTypes
from litellm.types.router import GenericLiteLLMParams
+from litellm.types.utils import CallTypes
# Mock the necessary dependencies
@pytest.fixture
-def setup_mocks():
+def setup_mocks(monkeypatch):
+ # Clear Azure environment variables that might interfere with tests
+ monkeypatch.delenv("AZURE_USERNAME", raising=False)
+ monkeypatch.delenv("AZURE_PASSWORD", raising=False)
+ monkeypatch.delenv("AZURE_CLIENT_SECRET", raising=False)
+ monkeypatch.delenv("AZURE_CLIENT_ID", raising=False)
+ monkeypatch.delenv("AZURE_TENANT_ID", raising=False)
+ monkeypatch.delenv("AZURE_SCOPE", raising=False)
+ monkeypatch.delenv("AZURE_AD_TOKEN", raising=False)
+
with patch(
"litellm.llms.azure.common_utils.get_azure_ad_token_from_entra_id"
) as mock_entra_token, patch(
@@ -1224,11 +1233,16 @@ def test_get_azure_ad_token_with_username_password_from_env(setup_mocks, monkeyp
assert token == "mock-username-password-token"
-def test_get_azure_ad_token_with_oidc_token(setup_mocks):
+def test_get_azure_ad_token_with_oidc_token(setup_mocks, monkeypatch):
"""Test get_azure_ad_token with OIDC token."""
# Reset mocks to ensure clean state
setup_mocks["oidc_token"].reset_mock()
+ # Clear environment variables that might interfere with OIDC token logic
+ monkeypatch.delenv("AZURE_USERNAME", raising=False)
+ monkeypatch.delenv("AZURE_PASSWORD", raising=False)
+ monkeypatch.delenv("AZURE_CLIENT_SECRET", raising=False)
+
# Create test parameters with OIDC token, client_id, and tenant_id
litellm_params = GenericLiteLLMParams(
azure_ad_token="oidc/test-token",
@@ -1237,7 +1251,9 @@ def test_get_azure_ad_token_with_oidc_token(setup_mocks):
azure_scope="test-azure-scope",
# Ensure no other auth methods are available
azure_ad_token_provider=None,
- client_secret=None
+ client_secret=None,
+ azure_username=None,
+ azure_password=None,
)
# Call the function
@@ -1258,9 +1274,13 @@ def test_get_azure_ad_token_with_oidc_token(setup_mocks):
assert token == "mock-oidc-token"
-def test_get_azure_ad_token_with_token_refresh(setup_mocks):
+def test_get_azure_ad_token_with_token_refresh(setup_mocks, monkeypatch):
"""Test get_azure_ad_token with token refresh enabled."""
# Reset mocks to ensure clean state
+ monkeypatch.delenv("AZURE_USERNAME", raising=False)
+ monkeypatch.delenv("AZURE_PASSWORD", raising=False)
+ monkeypatch.delenv("AZURE_CLIENT_SECRET", raising=False)
+
setup_mocks["token_provider"].reset_mock()
# Enable token refresh