Skip to content

fix: EnvHelper unusable if error occurs during initialisation #954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions code/backend/batch/utilities/helpers/env_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions code/tests/utilities/helpers/test_env_helper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from unittest.mock import patch
from pytest import MonkeyPatch
import pytest
from backend.batch.utilities.helpers.env_helper import EnvHelper
Expand Down Expand Up @@ -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
Loading