Fix flaky tests: OIDC Azure AD and video content handler GET

- test_oidc_azure_ad_token_success: use monkeypatch.delenv to force-unset
  AZURE_FEDERATED_TOKEN_FILE so the Azure AD token provider path is always
  exercised in CI (e.g. Azure Pipelines / GitHub Actions OIDC).
- test_video_content_handler_uses_get_for_openai: patch both
  http_handler._get_httpx_client and llm_http_handler._get_httpx_client so
  the mock is used regardless of import order / CI environment.
This commit is contained in:
Alexsander Hamir 2026-02-10 15:14:03 -08:00
parent bd1db74031
commit 9f26a1b494
2 changed files with 12 additions and 9 deletions

View file

@ -151,20 +151,18 @@ def test_oidc_azure_file_success(mock_env, tmp_path):
@patch("litellm.secret_managers.main.get_azure_ad_token_provider")
@patch.dict(os.environ, {}, clear=False) # Ensure AZURE_FEDERATED_TOKEN_FILE is not set
def test_oidc_azure_ad_token_success(mock_get_azure_ad_token_provider):
# Ensure the env var is not set so it falls through to Azure AD token provider
if "AZURE_FEDERATED_TOKEN_FILE" in os.environ:
del os.environ["AZURE_FEDERATED_TOKEN_FILE"]
def test_oidc_azure_ad_token_success(mock_get_azure_ad_token_provider, monkeypatch):
# Force-unset so we always hit the Azure AD token provider path (CI may set AZURE_FEDERATED_TOKEN_FILE)
monkeypatch.delenv("AZURE_FEDERATED_TOKEN_FILE", raising=False)
# Mock the token provider function that gets returned and called
mock_token_provider = Mock(return_value="azure_ad_token")
mock_get_azure_ad_token_provider.return_value = mock_token_provider
# Also mock the Azure Identity SDK to prevent any real Azure calls
with patch("azure.identity.get_bearer_token_provider") as mock_bearer:
mock_bearer.return_value = mock_token_provider
secret_name = "oidc/azure/api://azure-audience"
result = get_secret(secret_name)

View file

@ -798,7 +798,7 @@ def test_openai_transform_video_content_request_empty_params():
def test_video_content_handler_uses_get_for_openai():
"""HTTP handler must use GET (not POST) for OpenAI content download."""
from litellm.types.router import GenericLiteLLMParams
handler = BaseLLMHTTPHandler()
config = OpenAIVideoConfig()
@ -807,7 +807,12 @@ def test_video_content_handler_uses_get_for_openai():
mock_response.content = b"mp4-bytes"
mock_client.get.return_value = mock_response
# Patch both where _get_httpx_client is used and where it is defined so the mock
# is used regardless of import order / CI environment
with patch(
"litellm.llms.custom_httpx.http_handler._get_httpx_client",
return_value=mock_client,
), patch(
"litellm.llms.custom_httpx.llm_http_handler._get_httpx_client",
return_value=mock_client,
):