Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allure.environment is missing in allure.py #96

Open
1 of 3 tasks
OlegKuzovkov opened this issue Jul 12, 2017 · 16 comments
Open
1 of 3 tasks

allure.environment is missing in allure.py #96

OlegKuzovkov opened this issue Jul 12, 2017 · 16 comments

Comments

@OlegKuzovkov
Copy link

OlegKuzovkov commented Jul 12, 2017

I'm submitting a ...

  • bug report
  • feature request
  • support request => Please do not submit support request here, see note at the top of this template.

What is the current behavior?

Based on documentation here to apply some environment configurations we should use allure.environment(report='Allure report', browser=u'Я.Браузер') syntax. But in allure.py environment is missing. Before we have to use some environment.properties file in report folder to apply variables to the report. New functionality is missing.
Content of allure.py:

from allure_commons._allure import label
from allure_commons._allure import severity
from allure_commons._allure import tag
from allure_commons._allure import epic, feature, story
from allure_commons._allure import link
from allure_commons._allure import issue, testcase
from allure_commons._allure import Dynamic as dynamic
from allure_commons._allure import step
from allure_commons._allure import attach
from allure_commons.types import Severity as severity_level
from allure_commons.types import AttachmentType as attachment_type


__all__ = [
    'label',
    'severity',
    'tag',
    'epic'
    'feature',
    'story',

    'link',
    'issue',
    'testcase',

    'step'

    'dynamic'

    'severity_level',

    'attach',
    'attachment_type'
]

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

What is the expected behavior?

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

  • Allure version: 2.2.1
  • Test framework: pytest@3.5
  • Allure adaptor: allure-pytest@2.1.0b1

Other information

@OlegKuzovkov OlegKuzovkov changed the title allure.environment is missing allure.environment is missing in allure.py Jul 12, 2017
@antlong
Copy link

antlong commented Aug 18, 2017

I made a ticket also with this not working. +1

@mvoitko
Copy link

mvoitko commented Aug 22, 2017

+1

@antlong
Copy link

antlong commented Aug 22, 2017

@mvoitko
Copy link

mvoitko commented Aug 23, 2017

@antlong I am getting

INTERNALERROR>     allure.environment(ENV=environment_config,
INTERNALERROR> AttributeError: 'module' object has no attribute 'environment'

And the issue was confirmed in the respective gitter channel.

@sseliverstov
Copy link
Contributor

Environment is not implemented in 2x version.

@antlong
Copy link

antlong commented Aug 23, 2017 via email

@alexandr85
Copy link

@sseliverstov about 'Environment Parameters' wrote in documentation and we expect it
https://docs.qameta.io/allure/latest/#_pytest

@jurisbu
Copy link

jurisbu commented Oct 26, 2017

@sseliverstov If it is not implemented what is the suggested workaround then? Does this mean allure-python is feature incomplete and not ready for production? I am guessing that's why it is still BETA.

@Das-Sreedeep
Copy link

pytest: error: unrecognized arguments: --allure_severities=blocker
inifile: None

Getting this error even I mentioned this before defining a method

Categorise Severity

@pytest.allure.severity(pytest.allure.severity_level.BLOCKER)

@sseliverstov
Copy link
Contributor

sseliverstov commented Jul 7, 2018

yep allure still can't do environment( god bless the allure3

@rrudakov
Copy link

rrudakov commented Jul 15, 2018

As workaround it's possible to create environment.xml and put it to alluredir after all tests executions finished. For pytest I have written next code:

# conftest.py
@pytest.fixture(scope="session")
def allure_env(tmpdir_factory):
    """Provide access to environment file."""
    env = tmpdir_factory.mktemp("allure").join("environment.xml")
    environment = lxml.etree.Element("environment")
    with open(env, "a") as env_xml:
        env_xml.write(lxml.etree.tounicode(environment, pretty_print=True))

    return str(env)


@pytest.fixture(scope="session", autouse=True)
def write_allure_env(request, allure_env):
    """Copy environment to alluredir."""
    yield

    alluredir = request.config.getoption("--alluredir")
    if os.path.isdir(alluredir):
        copyfile(allure_env, os.path.join(alluredir, "environment.xml"))

# common.py
import lxml

def set_env(allure_env: str, name: str, val: str) -> None:
    """Add entry to environment.xml."""
    parser = lxml.etree.XMLParser(remove_blank_text=True)
    tree = lxml.etree.parse(allure_env, parser)
    env = tree.getroot()

    exist = tree.xpath(
        f"/environment/parameter[key[text()='{name}'] "
        f"and value[text()='{val}']]"
    )

    if not exist:
        parameter = lxml.etree.SubElement(env, "parameter")
        name_node = lxml.etree.SubElement(parameter, "key")
        name_node.text = name
        value_node = lxml.etree.SubElement(parameter, "value")
        value_node.text = val

        with open(allure_env, "w") as env_xml:
            env_xml.write(lxml.etree.tounicode(env, pretty_print=True))

# test_something.py
import common

def test_example(request, allure_env):
    """Example test function."""
    env = request.config.getoption("--env")
    if env == "test":
        common.set_env(allure_env, "Environment", "Test")
    else:
        common.set_env(allure_env, "Environment", "Production")

Hope this will be helplul)

@theObserver1
Copy link

Surely the above workaround will fail because allure considers the enviroment.xml in the allure-report dir as 'unclean' and refuse the generate without the --clean option?

@shpaker
Copy link

shpaker commented Mar 6, 2020

My implementation of the fixture for adding information to the Environment widget:

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)

Example of usage:

@fixture(autouse=True)
def cenpprop(add_allure_environment_property: Callable) -> None:
    add_allure_environment_property('foo', 3)
    add_allure_environment_property('bar', 'baz')

@teamdts
Copy link

teamdts commented May 19, 2020

@shpaker in this environmnet i want to add dynamic things like
browser name
browser version
environment like production/development/staging

so how i can add that dynamic things ?

@Khouloud-moalla
Copy link

@shpaker in this environmnet i want to add dynamic things like browser name browser version environment like production/development/staging

so how i can add that dynamic things ?

aany news for this!!

@andreabisello
Copy link

@shpaker thanks,
any more elegant implementation in september 2029?
the definition of environment is so important,
why this feature is missing in allure?
probably the mindset of the implementation is different,
but are we not suppose to easily set environment variable during test execution and result collecting?
i think is normal to have the same code tested against different environment, so i would aspect a easy definition of the environment, probably by a command line parameter, without the need to implement your fixture.
thanks for any suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests