Last active
March 6, 2020 14:10
-
-
Save shpaker/5ad803ae0e3f0310f08e1049272bc308 to your computer and use it in GitHub Desktop.
Implementation of the pytest fixture for adding information to the Environment widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import path | |
from typing import Any, Callable, Optional | |
from _pytest.fixtures import SubRequest | |
from pytest import fixture | |
ALLURE_ENVIRONMENT_PROPERTIES_FILE = 'environment.properties' | |
ALLUREDIR_OPTION = '--alluredir' | |
@fixture(scope='session', autouse=True) | |
def add_allure_environment_property(request: SubRequest) -> Optional[Callable]: | |
environment_properties = dict() | |
def maker(key: str, value: Any): | |
environment_properties.update({key: value}) | |
yield maker | |
alluredir = request.config.getoption(ALLUREDIR_OPTION) | |
if not alluredir or not path.isdir(alluredir) or not environment_properties: | |
return | |
allure_env_path = path.join(alluredir, ALLURE_ENVIRONMENT_PROPERTIES_FILE) | |
with open(allure_env_path, 'w') as _f: | |
data = '\n'.join([f'{variable}={value}' for variable, value in environment_properties.items()]) | |
_f.write(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment