code: def test_catboost_pruning_callback_errors(
      metric: str, eval_set_index: int
  ) -> None:
      # This test aims to cover the ValueError block in CatBoostPruningCallback.after_iteration().
      # However, catboost currently terminates with a SystemError when python>=3.9 or pytest>=7.2.0,
      # otherwise terminates with RecursionError. This is because after_iteration() is called in a
      # Cython function in the catboost library, which is causing the unexpected error behavior.
      # Note that the difference in error type is mainly because the _Py_CheckRecursionLimit
      # variable used in limited C API was removed after python 3.9.
  
      def objective(trial: optuna.trial.Trial) -> float:
          train_x = np.asarray([[1.0], [2.0]])
          train_y = np.asarray([[1.0], [0.0]])
          valid_x = np.asarray([[1.0], [2.0]])
          valid_y = np.asarray([[1.0], [0.0]])
  
          pruning_callback = CatBoostPruningCallback(
              trial, metric, eval_set_index
          )
          param = {
              "objective": "Logloss",
              "eval_metric": "AUC",
          }
  
          gbm = cb.CatBoostClassifier(**param)
          gbm.fit(
              train_x,
              train_y,
              eval_set=[(valid_x, valid_y)],
              verbose=0,
              callbacks=[pruning_callback],
          )
  
          # Invoke pruning manually.
          pruning_callback.check_pruned()
  
          return 1.0
  
      # Unknown validation name or metric.
      study = optuna.create_study(pruner=DeterministicPruner(False))
  
      with pytest.raises(ValueError):
          study.optimize(objective, n_trials=1)
  
file_path: optuna/tests/integration_tests/test_catboost.py
imports: import types
  import numpy
  import pytest
  import optuna
  from optuna._imports import try_import
  from optuna.integration.catboost import CatBoostPruningCallback
  from optuna.testing.pruners import DeterministicPruner
label_desc: Use image node_id 3 for calling a global function with example usage: test_catboost_pruning_callback_errors(metric, eval_set_index) and returns: int