def test_custom_azure_ad_token_provider(sync_azure_openai_mock: MagicMock):
    """
    Verify that a custom azure ad token provider set for AzureOpenAI.
    """

    def custom_azure_ad_token_provider() -> str:
        return "mock_api_key"

    mock_instance = sync_azure_openai_mock.return_value
    # Valid mocked result required to not run into another error
    mock_instance.chat.completions.create.return_value = mock_chat_completion_v1()
    azure_openai = AzureOpenAI(
        engine="foo bar",
        use_azure_ad=True,
        azure_ad_token_provider=custom_azure_ad_token_provider,
    )
    azure_openai.complete("test prompt")
    assert azure_openai.api_key == "mock_api_key"

    Verify that a custom azure ad token provider set for AzureOpenAI.
    
llama-index-integrations/llms/llama-index-llms-azure-openai/tests/test_azure_openai.py