code: def test_retry_with_max_failures(ray_start_4_cpus, eventual_success):
      """Test auto-resume of a Train run when setting max_failures > 0."""
  
      num_failures = 2 if eventual_success else 3
      max_retries = 2
      final_iter = 10
  
      def train_func():
          ckpt = train.get_checkpoint()
          itr = 1
          restore_count = 0
          if ckpt:
              ckpt = load_dict_checkpoint(ckpt)
              itr = ckpt["iter"] + 1
              restore_count = ckpt["restore_count"] + 1
  
          for i in range(itr, final_iter + 1):
              with create_dict_checkpoint(
                  dict(iter=i, restore_count=restore_count)
              ) as checkpoint:
                  train.report(
                      dict(test=i, training_iteration=i),
                      checkpoint=checkpoint,
                  )
              if restore_count < num_failures:
                  raise RuntimeError("try to fail me")
  
      trainer = DataParallelTrainer(
          train_func,
          scaling_config=ScalingConfig(num_workers=2),
          run_config=RunConfig(
              failure_config=train.FailureConfig(
                  max_failures=max_retries
              )
          ),
      )
  
      if not eventual_success:
          # If we gave up due to hitting our max retry attempts,
          # then `trainer.fit` should raise the last error we encountered.
          with pytest.raises(TrainingFailedError):
              trainer.fit()
      else:
          # If we encounter errors but eventually succeed, `trainer.fit` should NOT
          # raise any of those errors.
          result = trainer.fit()
          assert not result.error
          checkpoint = load_dict_checkpoint(result.checkpoint)
          assert checkpoint["iter"] == final_iter
  
imports: import warnings
  from pathlib import Path
  from typing import Dict, List
  import pytest
  import ray
  from ray import train
  from ray.air._internal.uri_utils import URI
  from ray.train import CheckpointConfig, RunConfig, ScalingConfig
  from ray.train.base_trainer import BaseTrainer
  from ray.train.data_parallel_trainer import DataParallelTrainer
  from ray.train.lightgbm import LightGBMTrainer
  from ray.train.tests.util import create_dict_checkpoint, load_dict_checkpoint
  from ray.train.torch import TorchTrainer
  from ray.train.trainer import TrainingFailedError
  from ray.train.xgboost import XGBoostTrainer
  from ray.tune import Callback
  from ray.tune.experiment import Trial
label_desc: Use image node_id 11 for calling a global function with example usage: test_retry_with_max_failures(ray_start_4_cpus, eventual_success) without return types