Skip to content

Commit

Permalink
LIN-740: Reset configurations (LineaLabs#870)
Browse files Browse the repository at this point in the history
Some MLflow tests require setting some configuration flags using  which are not reset by default, which leads to subsequent tests failing due to unexpected configuration. Hence, for such tests, we reset the  as well as the env variables to tackle the bug.
  • Loading branch information
aayan636 authored Jan 11, 2023
1 parent 2adffd6 commit 5571fcd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ def __call__(
f"lineapy.{save.__name__}({artifact}, {repr(artifact)})\n"
)

# Saving old env variables to reset after test is executed
old_os_environ = dict(os.environ)
# These temp filenames are unique per test function.
# If `execute` is called twice in a test, it will overwrite the
# previous paths
Expand Down Expand Up @@ -247,6 +249,13 @@ def __call__(
new_executor.execute_graph(tracer.graph)
os.chdir(current_working_dir)

# Reset environment variables to state before the user code was executed
# so as to not affect subsequently executed tests.
for key in os.environ.keys():
del os.environ[key]
for key in old_os_environ:
os.environ[key] = old_os_environ[key]

return tracer


Expand Down
2 changes: 2 additions & 0 deletions tests/test_mlflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def test_save_get_delete_to_mlflow(execute):
deleted_clf = lineapy.get('clf', version=art.version)
except:
deleted_clf = None
lineapy.options.set('mlflow_tracking_uri',None)
lineapy.options.set('mlflow_registry_uri',None)
"""
res = execute(code, snapshot=False)

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/utils/test_config_mlflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ def test_mlflow_console_config():
clean_lineapy_env_var()
for k, v in existing_lineapy_env.items():
os.environ[k] = v

# Reset MLFlow options to not affect subsequent tests
options.set("mlflow_tracking_uri", None)
options.set("default_ml_models_storage_backend", None)

0 comments on commit 5571fcd

Please sign in to comment.