code: def test_run_trial_pruned(
      storage_mode: str, caplog: LogCaptureFixture
  ) -> None:
      def gen_func(
          intermediate: Optional[float] = None,
      ) -> Callable[[Trial], float]:
          def func(trial: Trial) -> float:
              if intermediate is not None:
                  trial.report(step=1, value=intermediate)
              raise TrialPruned
  
          return func
  
      with StorageSupplier(storage_mode) as storage:
          study = create_study(storage=storage)
  
          caplog.clear()
          frozen_trial = _optimize._run_trial(
              study, gen_func(), catch=()
          )
          assert frozen_trial.state == TrialState.PRUNED
          assert frozen_trial.value is None
          assert "Trial 0 pruned." in caplog.text
  
          caplog.clear()
          frozen_trial = _optimize._run_trial(
              study, gen_func(intermediate=1), catch=()
          )
          assert frozen_trial.state == TrialState.PRUNED
          assert frozen_trial.value == 1
          assert "Trial 1 pruned." in caplog.text
  
          caplog.clear()
          frozen_trial = _optimize._run_trial(
              study, gen_func(intermediate=float("nan")), catch=()
          )
          assert frozen_trial.state == TrialState.PRUNED
          assert frozen_trial.value is None
          assert "Trial 2 pruned." in caplog.text
  
imports: from typing import Callable
  from typing import Generator
  from typing import Optional
  from unittest import mock
  from _pytest.logging import LogCaptureFixture
  import pytest
  from optuna import create_study
  from optuna import logging
  from optuna import Trial
  from optuna import TrialPruned
  from optuna.study import _optimize
  from optuna.study._tell import _tell_with_warning
  from optuna.study._tell import STUDY_TELL_WARNING_KEY
  from optuna.testing.objectives import fail_objective
  from optuna.testing.storages import STORAGE_MODES
  from optuna.testing.storages import StorageSupplier
  from optuna.trial import TrialState
label_desc: Use image node_id 4 for calling a global function with example usage: test_run_trial_pruned(storage_mode, caplog) and returns: func