def test_prepare_chat_with_tools_explicit_tool_choice_overrides_tool_required():
    """Test that explicit tool_choice overrides tool_required in OpenAIResponses."""
    # Create mock clients to avoid API calls
    mock_sync_client = MagicMock()
    mock_async_client = MagicMock()

    llm = OpenAIResponses(api_key="test-key")
    llm._client = mock_sync_client
    llm._aclient = mock_async_client

    # Create a simple tool for testing
    def search(query: str) -> str:
        """Search for information about a query."""
        return f"Results for {query}"

    search_tool = FunctionTool.from_defaults(
        fn=search, name="search_tool", description="A tool for searching information"
    )

    # Test that explicit tool_choice overrides tool_required
    result = llm._prepare_chat_with_tools(
        tools=[search_tool], tool_required=True, tool_choice="none"
    )

    assert result["tool_choice"] == "none"  # Should be "none" not "required"
    assert len(result["tools"]) == 1
    assert result["tools"][0]["name"] == "search_tool"
Test that explicit tool_choice overrides tool_required in OpenAIResponses.
llama-index-integrations/llms/llama-index-llms-openai/tests/test_openai_responses.py