diff --git a/code/backend/batch/utilities/helpers/env_helper.py b/code/backend/batch/utilities/helpers/env_helper.py index 7319c0499..96819b0c6 100644 --- a/code/backend/batch/utilities/helpers/env_helper.py +++ b/code/backend/batch/utilities/helpers/env_helper.py @@ -15,8 +15,9 @@ class EnvHelper: def __new__(cls): with cls._lock: if cls._instance is None: - cls._instance = super(EnvHelper, cls).__new__(cls) - cls._instance.__load_config() + instance = super(EnvHelper, cls).__new__(cls) + instance.__load_config() + cls._instance = instance return cls._instance def __load_config(self, **kwargs) -> None: diff --git a/code/tests/utilities/helpers/test_env_helper.py b/code/tests/utilities/helpers/test_env_helper.py index aff7090bc..10e1de308 100644 --- a/code/tests/utilities/helpers/test_env_helper.py +++ b/code/tests/utilities/helpers/test_env_helper.py @@ -1,3 +1,4 @@ +from unittest.mock import patch from pytest import MonkeyPatch import pytest from backend.batch.utilities.helpers.env_helper import EnvHelper @@ -140,3 +141,16 @@ def test_use_advanced_image_processing(monkeypatch: MonkeyPatch, value, expected # then assert actual_use_advanced_image_processing == expected + + +@patch( + "backend.batch.utilities.helpers.env_helper.os.getenv", + side_effect=Exception("Some error"), +) +def test_env_helper_not_created_if_error_occurs(_): + # when + with pytest.raises(Exception): + EnvHelper() + + # then + assert EnvHelper._instance is None