def test_prepare_chat_with_tools_explicit_tool_choice_required():
    """Test that explicit tool_choice="required" works even when tool_required=False."""
    llm = OpenAI(api_key="test-key")

    result = llm._prepare_chat_with_tools(
        tools=[search_tool],
        user_msg="Search for Python tutorials",
        tool_required=False,
        tool_choice="required",
    )

    assert result["tool_choice"] == "required"
Test that explicit tool_choice="required" works even when tool_required=False.
llama-index-integrations/llms/llama-index-llms-openai/tests/test_llms_openai.py