Automatically restore environment variables after each unit test to avoid flakiness
@@ -407,6 +407,16 @@ def request_mocker(request):
return m
+@pytest.fixture(autouse=True)
+def preserve_environ():
+ environ = dict(os.environ)
+ try:
+ yield
+ finally:
+ os.environ.clear()
+ os.environ.update(environ)
+
+
@pytest.fixture(autouse=True)
def check_environ():
"""Warn about WANDB_ environment variables the user has set
