code: def test_attributes_from_environment_variables(monkeypatch):
      """Test that the default cluster environment takes the attributes from the environment variables."""
      if _XLA_GREATER_EQUAL_2_1:
          from torch_xla import runtime
  
          monkeypatch.setattr(runtime, "world_size", lambda: 2)
          monkeypatch.setattr(runtime, "global_ordinal", lambda: 0)
          monkeypatch.setattr(runtime, "local_ordinal", lambda: 2)
          monkeypatch.setattr(runtime, "host_index", lambda: 1)
      else:
          from torch_xla.experimental import pjrt
  
          monkeypatch.setattr(pjrt, "world_size", lambda: 2)
          monkeypatch.setattr(pjrt, "global_ordinal", lambda: 0)
          monkeypatch.setattr(pjrt, "local_ordinal", lambda: 2)
          os.environ["XRT_HOST_ORDINAL"] = "1"
  
      env = XLAEnvironment()
      with pytest.raises(NotImplementedError):
          _ = env.main_address
      with pytest.raises(NotImplementedError):
          _ = env.main_port
      assert env.world_size() == 2
      assert env.global_rank() == 0
      assert env.local_rank() == 2
      assert env.node_rank() == 1
      env.set_global_rank(100)
      assert env.global_rank() == 0
      env.set_world_size(100)
      assert env.world_size() == 2
  
file_path: pytorch-lightning/tests/tests_fabric/plugins/environments/test_xla.py
imports: import os
  from unittest import mock
  import lightning.fabric
  import pytest
  from lightning.fabric.accelerators.xla import _XLA_GREATER_EQUAL_2_1
  from lightning.fabric.plugins.environments import XLAEnvironment
  from tests_fabric.helpers.runif import RunIf
label_desc: Use image node_id 2 for calling a global function with example usage: test_attributes_from_environment_variables(monkeypatch) without return types