code: def test_ValueError_evaluate_grid_hyperparameters_when_return_best_and_len_y_exog_different():
      """
      Test ValueError is raised in _evaluate_grid_hyperparameters when return_best
      and length of `y` and `exog` do not match.
      """
      forecaster = ForecasterAutoreg(
          regressor=Ridge(random_state=123), lags=2
      )
      exog = y[:30]
  
      err_msg = re.escape(
          (
              f"`exog` must have same number of samples as `y`. "
              f"length `exog`: ({len(exog)}), length `y`: ({len(y)})"
          )
      )
      with pytest.raises(ValueError, match=err_msg):
          _evaluate_grid_hyperparameters(
              forecaster=forecaster,
              y=y,
              exog=exog,
              lags_grid=[2, 4],
              param_grid=[
                  {"alpha": 0.01},
                  {"alpha": 0.1},
                  {"alpha": 1},
              ],
              steps=3,
              refit=False,
              metric="mean_absolute_error",
              initial_train_size=len(y[:-12]),
              fixed_train_size=False,
              return_best=True,
              verbose=False,
          )
  
imports: import re
  import pytest
  import numpy
  import pandas
  from sklearn.linear_model import Ridge
  from sklearn.metrics import mean_absolute_error
  from sklearn.metrics import mean_absolute_percentage_error
  from skforecast.ForecasterAutoreg import ForecasterAutoreg
  from skforecast.ForecasterAutoregCustom import ForecasterAutoregCustom
  from skforecast.model_selection.model_selection import _evaluate_grid_hyperparameters
  from tqdm import tqdm
  from functools import partialmethod
  from .fixtures_model_selection import y
label_desc: Use image node_id 2 for calling a global function with example usage: test_ValueError_evaluate_grid_hyperparameters_when_return_best_and_len_y_exog_different() without return types