code: def test_ranks_available_automatic_strategy_selection(
      cuda_count_4, trainer_kwargs
  ):
      """Test that the rank information is readily available after Trainer initialization."""
      num_nodes = 2
      trainer_kwargs.update(num_nodes=num_nodes)
  
      for cluster, variables, expected in environment_combinations():
          if trainer_kwargs["strategy"] == "ddp_spawn":
              if isinstance(
                  cluster, (SLURMEnvironment, TorchElasticEnvironment)
              ):
                  # slurm and torchelastic do not work with spawn strategies
                  continue
              # when using spawn, we don't reach rank > 0 until we call Trainer.fit()
              # LOCAL_RANK is only set after we spawned
              if "LOCAL_RANK" not in variables:
                  expected.update(
                      global_rank=(expected["node_rank"] * 2),
                      local_rank=0,
                  )
  
          with mock.patch.dict(os.environ, variables):
              trainer = Trainer(**trainer_kwargs)
              assert type(trainer.strategy.cluster_environment) is type(
                  cluster
              )
              assert rank_zero_only.rank == expected["global_rank"]
              assert trainer.global_rank == expected["global_rank"]
              assert trainer.local_rank == expected["local_rank"]
              assert trainer.node_rank == expected["node_rank"]
              assert trainer.world_size == expected["world_size"]
  
file_path: pytorch-lightning/tests/tests_pytorch/plugins/test_cluster_integration.py
imports: import os
  from unittest import mock
  import pytest
  import torch
  from lightning.fabric.plugins.environments import LightningEnvironment, SLURMEnvironment, TorchElasticEnvironment
  from lightning.pytorch import Trainer
  from lightning.pytorch.strategies import DDPStrategy, DeepSpeedStrategy
  from lightning.pytorch.utilities.rank_zero import rank_zero_only
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 3 for calling a global function with example usage: test_ranks_available_automatic_strategy_selection(cuda_count_4, trainer_kwargs) without return types