def test_prepare_chat_with_tools_no_tools(mock_resolve_credentials, MockModelInference):
    """Test that tool_required=True with no tools doesn't add a tool_choice."""
    mock_resolve_credentials.return_value = {}
    mock_instance = MockModelInference.return_value

    llm = WatsonxLLM(
        model_id="test_model",
        project_id="test_project",
        apikey="test_apikey",
        url="https://test-url.com",
        api_client=MagicMock(),  # Use mock client to bypass credential checks
    )

    # Test with tool_required=True but no tools
    result = llm._prepare_chat_with_tools(tools=[], tool_required=True)

    # When there are no tools, tool_choice should not be specified even if tool_required=True
    assert "tool_choice" not in result
    assert result["tools"] is None
Test that tool_required=True with no tools doesn't add a tool_choice.
llama-index-integrations/llms/llama-index-llms-ibm/tests/test_tool_required.py