code: def test_run_iterator(ray_start_4_cpus):
      config = BackendConfig()
  
      def train_func():
          for i in range(3):
              train.report(dict(index=i))
          return 1
  
      iterator = create_iterator(train_func, config)
  
      count = 0
      for results in iterator:
          assert all(
              value.metrics["index"] == count for value in results
          )
          count += 1
  
      assert count == 3
      assert iterator.is_finished()
  
      with pytest.raises(StopIteration):
          next(iterator)
  
imports: import functools
  import time
  from unittest.mock import patch
  import pytest
  import ray
  from ray import train
  from ray.air._internal.util import StartTraceback
  from ray.train import DataConfig
  from ray.train._internal.backend_executor import BackendExecutor
  from ray.train._internal.session import get_session, init_session
  from ray.train._internal.utils import construct_train_func
  from ray.train._internal.worker_group import WorkerGroup
  from ray.train.backend import BackendConfig
  from ray.train.examples.pytorch.torch_linear_example import train_func
  from ray.train.examples.tf.tensorflow_mnist_example import train_func
  from ray.train.tests.util import mock_storage_context
  from ray.train.trainer import TrainingIterator
label_desc: Use image node_id 6 for calling a global function with example usage: test_run_iterator(ray_start_4_cpus) and returns: int