Skip to content

Commit b7a22ba

Browse files
authored
CI: fixture for global rank variable reset (#6839)
1 parent a17c027 commit b7a22ba

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
import torch.multiprocessing as mp
2222

2323

24+
@pytest.fixture(scope="function", autouse=True)
25+
def preserve_global_rank_variable():
26+
""" Ensures that the rank_zero_only.rank global variable gets reset in each test. """
27+
from pytorch_lightning.utilities.distributed import rank_zero_only
28+
rank = getattr(rank_zero_only, "rank", None)
29+
yield
30+
if rank is not None:
31+
setattr(rank_zero_only, "rank", rank)
32+
33+
2434
@pytest.fixture(scope="function", autouse=True)
2535
def restore_env_variables():
2636
""" Ensures that environment variables set during the test do not leak out. """

0 commit comments

Comments
 (0)