From db70a49badd44537e7de1e80481e15cb235a57e9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 Dec 2023 11:32:30 +0100 Subject: [PATCH] add file exists check to load_json_to_environ --- pytest_abra/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pytest_abra/utils.py b/pytest_abra/utils.py index 407df11..b9fcb2d 100644 --- a/pytest_abra/utils.py +++ b/pytest_abra/utils.py @@ -7,6 +7,8 @@ from datetime import datetime from pathlib import Path from urllib.parse import urlunparse +from loguru import logger + @dataclass class BaseUrl: @@ -28,7 +30,7 @@ def get_datetime_string() -> str: return current_datetime.strftime("%Y-%m-%d-%H-%M-%S") -def rmtree(root_dir: Path): +def rmtree(root_dir: Path) -> None: """removes a folder with content recursively""" if not root_dir.is_dir(): return @@ -50,8 +52,13 @@ def generate_random_string(length: int, punctuation=False) -> str: return random_string -def load_json_to_environ(cred_file: Path): +def load_json_to_environ(cred_file: Path) -> None: """Load the contents of a json file directly into os.environ. Variable names are inherited""" + + if not cred_file.is_file(): + logger.warning(f"{cred_file} could not be found, no credentials loaded") + return + with open(cred_file, "r") as f: CREDENTIALS = json.load(f)