frostfs-testcases/pytest_tests/helpers/env_properties.py
Vladimir Domnich d6861f4f62 Refactor env properties
Encapculate reading/writing environment.properties in helper.

Signed-off-by: Vladimir Domnich <v.domnich@yadro.com>
2022-08-15 18:49:05 +04:00

40 lines
1.2 KiB
Python

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