Skip to content

Commit

Permalink
CI: fixture for global rank variable reset (#6839)
Browse files Browse the repository at this point in the history
  • Loading branch information
awaelchli authored Apr 6, 2021
1 parent a17c027 commit b7a22ba
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
import torch.multiprocessing as mp


@pytest.fixture(scope="function", autouse=True)
def preserve_global_rank_variable():
""" Ensures that the rank_zero_only.rank global variable gets reset in each test. """
from pytorch_lightning.utilities.distributed import rank_zero_only
rank = getattr(rank_zero_only, "rank", None)
yield
if rank is not None:
setattr(rank_zero_only, "rank", rank)


@pytest.fixture(scope="function", autouse=True)
def restore_env_variables():
""" Ensures that environment variables set during the test do not leak out. """
Expand Down

0 comments on commit b7a22ba

Please sign in to comment.