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
Test that rank environment variables are properly checked for rank_zero_only.
tests/tests_fabric/utilities/test_rank_zero.py