Skip to content

Commit

Permalink
fix: EnvHelper unusable if error occurs during initialisation (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
cecheta authored May 21, 2024
1 parent 0d1f2e0 commit 290fb05
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit 290fb05

Please sign in to comment.