From 38427b5eecb38b6ffdc2494826907fe542c025b6 Mon Sep 17 00:00:00 2001 From: Toke Jepsen Date: Thu, 12 Oct 2023 11:07:09 +0100 Subject: [PATCH] Testing: Inject mongo_url argument earlier (#5706) * Inject mongo_url argument earlier * monkeypatch instead of os.environ --------- Co-authored-by: Petr Kalis --- tests/lib/testing_classes.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/lib/testing_classes.py b/tests/lib/testing_classes.py index e82e438e545..277b332e19c 100644 --- a/tests/lib/testing_classes.py +++ b/tests/lib/testing_classes.py @@ -105,7 +105,7 @@ def output_folder_url(self, download_test_data): yield path @pytest.fixture(scope="module") - def env_var(self, monkeypatch_session, download_test_data): + def env_var(self, monkeypatch_session, download_test_data, mongo_url): """Sets temporary env vars from json file.""" env_url = os.path.join(download_test_data, "input", "env_vars", "env_var.json") @@ -129,6 +129,9 @@ def env_var(self, monkeypatch_session, download_test_data): monkeypatch_session.setenv(key, str(value)) #reset connection to openpype DB with new env var + if mongo_url: + monkeypatch_session.setenv("OPENPYPE_MONGO", mongo_url) + import openpype.settings.lib as sett_lib sett_lib._SETTINGS_HANDLER = None sett_lib._LOCAL_SETTINGS_HANDLER = None @@ -150,8 +153,7 @@ def db_setup(self, download_test_data, env_var, monkeypatch_session, request, mongo_url): """Restore prepared MongoDB dumps into selected DB.""" backup_dir = os.path.join(download_test_data, "input", "dumps") - - uri = mongo_url or os.environ.get("OPENPYPE_MONGO") + uri = os.environ.get("OPENPYPE_MONGO") db_handler = DBHandler(uri) db_handler.setup_from_dump(self.TEST_DB_NAME, backup_dir, overwrite=True,