From 2f6d0c47e59f312534ab66a32eead59b2c7027c1 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 11 Dec 2023 00:12:51 +0100 Subject: [PATCH] add load_json_to_environ --- main.py | 10 +++------- pytest_abra/utils.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index aa809bc..9a37f57 100644 --- a/main.py +++ b/main.py @@ -1,16 +1,12 @@ -import json -import os import subprocess from pathlib import Path +from pytest_abra.utils import load_json_to_environ + # --------------------- load credentials to env variables -------------------- # cred_file = Path("credentials.json") -with open(cred_file, "r") as f: - CREDENTIALS = json.load(f) - -for key, value in CREDENTIALS.items(): - os.environ[key] = value +load_json_to_environ(cred_file) # --------------------------------- env files -------------------------------- # diff --git a/pytest_abra/utils.py b/pytest_abra/utils.py index b5bd3cf..6de521c 100644 --- a/pytest_abra/utils.py +++ b/pytest_abra/utils.py @@ -1,3 +1,5 @@ +import json +import os import random import string from dataclasses import dataclass @@ -46,3 +48,11 @@ def generate_random_string(length: int, punctuation=False) -> str: characters += string.punctuation random_string = "".join(random.choice(characters) for _ in range(length)) return random_string + + +def load_json_to_environ(cred_file: Path): + with open(cred_file, "r") as f: + CREDENTIALS = json.load(f) + + for key, value in CREDENTIALS.items(): + os.environ[key] = value