Testing: Inject mongo_url argument earlier (#5706)

* Inject mongo_url argument earlier

* monkeypatch instead of os.environ

---------

Co-authored-by: Petr Kalis <petr.kalis@gmail.com>
This commit is contained in:
Toke Jepsen 2023-10-12 11:07:09 +01:00 committed by GitHub
parent e7cd31f2dd
commit 38427b5eec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -105,7 +105,7 @@ class ModuleUnitTest(BaseTest):
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 @@ class ModuleUnitTest(BaseTest):
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 @@ class ModuleUnitTest(BaseTest):
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,