code: def test_results_output_bayesian_search_optuna_ForecasterAutoreg_with_mocked_when_kwargs_study_optimize():
      """
      Test output of _bayesian_search_optuna in ForecasterAutoreg when
      kwargs_study_optimize with mocked (mocked done in Skforecast v0.4.3).
      """
      forecaster = ForecasterAutoreg(
          regressor=RandomForestRegressor(random_state=123),
          lags=2,  # Placeholder, the value will be overwritten
      )
  
      steps = 3
      n_validation = 12
      y_train = y[:-n_validation]
      lags_grid = [2, 4]
  
      def search_space(trial):
          search_space = {
              "n_estimators": trial.suggest_int(
                  "n_estimators", 100, 200
              ),
              "max_depth": trial.suggest_int(
                  "max_depth", 20, 35, log=True
              ),
              "max_features": trial.suggest_categorical(
                  "max_features", ["log2", "sqrt"]
              ),
          }
  
          return search_space
  
      # kwargs_study_optimize
      timeout = 2.0
  
      results = _bayesian_search_optuna(
          forecaster=forecaster,
          y=y,
          lags_grid=lags_grid,
          search_space=search_space,
          steps=steps,
          metric="mean_absolute_error",
          refit=True,
          initial_train_size=len(y_train),
          fixed_train_size=True,
          n_trials=10,
          random_state=123,
          n_jobs=1,
          return_best=False,
          verbose=False,
          kwargs_study_optimize={"timeout": timeout},
      )[0].reset_index(drop=True)
  
      expected_results = (
          pd.DataFrame(
              {
                  "lags": [
                      [1, 2],
                      [1, 2],
                      [1, 2],
                      [1, 2, 3, 4],
                      [1, 2, 3, 4],
                      [1, 2, 3, 4],
                  ],
                  "params": [
                      {
                          "n_estimators": 170,
                          "max_depth": 23,
                          "max_features": "sqrt",
                      },
                      {
                          "n_estimators": 172,
                          "max_depth": 25,
                          "max_features": "log2",
                      },
                      {
                          "n_estimators": 148,
                          "max_depth": 25,
                          "max_features": "sqrt",
                      },
                      {
                          "n_estimators": 170,
                          "max_depth": 23,
                          "max_features": "sqrt",
                      },
                      {
                          "n_estimators": 172,
                          "max_depth": 25,
                          "max_features": "log2",
                      },
                      {
                          "n_estimators": 148,
                          "max_depth": 25,
                          "max_features": "sqrt",
                      },
                  ],
                  "mean_absolute_error": np.array(
                      [
                          0.21698591071568632,
                          0.21677310983527143,
                          0.2207701537612612,
                          0.22227287699019596,
                          0.22139945523255808,
                          0.22838451457770267,
                      ]
                  ),
                  "n_estimators": np.array(
                      [170, 172, 148, 170, 172, 148]
                  ),
                  "max_depth": np.array([23, 25, 25, 23, 25, 25]),
                  "max_features": [
                      "sqrt",
                      "log2",
                      "sqrt",
                      "sqrt",
                      "log2",
                      "sqrt",
                  ],
              },
              index=pd.RangeIndex(start=0, stop=6, step=1),
          )
          .sort_values(by="mean_absolute_error", ascending=True)
          .reset_index(drop=True)
      )
  
      pd.testing.assert_frame_equal(
          results.head(2), expected_results.head(2), check_dtype=False
      )
  
imports: import re
  import pytest
  import numpy
  import pandas
  import sys
  from sklearn.ensemble import RandomForestRegressor
  from sklearn.linear_model import Ridge
  from sklearn.metrics import mean_absolute_error
  from skforecast.ForecasterAutoreg import ForecasterAutoreg
  from skforecast.ForecasterAutoregCustom import ForecasterAutoregCustom
  from skforecast.model_selection import backtesting_forecaster
  from skforecast.model_selection.model_selection import _bayesian_search_optuna
  import optuna
  from optuna.samplers import TPESampler
  from tqdm import tqdm
  from functools import partialmethod
  from .fixtures_model_selection import y
label_desc: Use image node_id 7 for calling a global function with example usage: test_results_output_bayesian_search_optuna_ForecasterAutoreg_with_mocked_when_kwargs_study_optimize() and returns: search_space