code: def test_rank_zero_known_environment_variables(
      env_vars, expected, monkeypatch
  ):
      """Test that rank environment variables are properly checked for rank_zero_only."""
      with mock.patch.dict(os.environ, env_vars):
          # force module reload to re-trigger the rank_zero_only.rank global computation
          monkeypatch.delitem(
              sys.modules,
              "lightning_utilities.core.rank_zero",
              raising=False,
          )
          monkeypatch.delitem(
              sys.modules,
              "lightning.fabric.utilities.rank_zero",
              raising=False,
          )
          from lightning.fabric.utilities.rank_zero import (
              rank_zero_only,
          )
  
          @rank_zero_only
          def foo():
              return 1
  
          assert foo() == expected
  
imports: import os
  import sys
  from unittest import mock
  import pytest
  from lightning.fabric.utilities.rank_zero import _get_rank
label_desc: Use image node_id 1 for calling a global function with example usage: test_rank_zero_known_environment_variables(env_vars, expected, monkeypatch) and returns: int