2022-08-08 16:51:28 +00:00
|
|
|
import logging
|
|
|
|
import re
|
|
|
|
|
|
|
|
import allure
|
|
|
|
from pytest import Config
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
2022-08-08 16:51:28 +00:00
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.step("Read environment.properties")
|
2022-08-08 16:51:28 +00:00
|
|
|
def read_env_properties(config: Config) -> dict:
|
2022-09-28 12:07:16 +00:00
|
|
|
environment_dir = config.getoption("--alluredir")
|
2022-08-08 16:51:28 +00:00
|
|
|
if not environment_dir:
|
|
|
|
return None
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
file_path = f"{environment_dir}/environment.properties"
|
|
|
|
with open(file_path, "r") as file:
|
2022-08-08 16:51:28 +00:00
|
|
|
raw_content = file.read()
|
|
|
|
|
|
|
|
env_properties = {}
|
2022-09-28 12:07:16 +00:00
|
|
|
for line in raw_content.split("\n"):
|
|
|
|
m = re.match("(.*?)=(.*)", line)
|
2022-08-08 16:51:28 +00:00
|
|
|
if not m:
|
2022-09-28 12:07:16 +00:00
|
|
|
logger.warning(f"Could not parse env property from {line}")
|
2022-08-08 16:51:28 +00:00
|
|
|
continue
|
|
|
|
key, value = m.group(1), m.group(2)
|
|
|
|
env_properties[key] = value
|
|
|
|
return env_properties
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.step("Update data in environment.properties")
|
2022-08-08 16:51:28 +00:00
|
|
|
def save_env_properties(config: Config, env_data: dict) -> None:
|
2022-09-28 12:07:16 +00:00
|
|
|
environment_dir = config.getoption("--alluredir")
|
2022-08-08 16:51:28 +00:00
|
|
|
if not environment_dir:
|
|
|
|
return None
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
file_path = f"{environment_dir}/environment.properties"
|
|
|
|
with open(file_path, "a+") as env_file:
|
2022-08-08 16:51:28 +00:00
|
|
|
for env, env_value in env_data.items():
|
2022-09-28 12:07:16 +00:00
|
|
|
env_file.write(f"{env}={env_value}\n")
|