问题
I want to customize my allure test report using pytest adaptor
. For e.g adding Environment details on the Overview Page. Changing the Report Name on the Overview screen.
I tried adding the environment details in conftest.py
as suggested in the documentation, but it do not work for me
def pytest_configure(config):
allure.environment(test_server='testserver', report='My Test Report')
I also tried adding environment.properties
in the allure-report folder but that also didn't work.
Please let me know if I am doing something wrong here and how can I resolve this problem.
回答1:
better late than never, as said in documentation pytest_configure is
called after command line options have been parsed and all plugins and initial conftest files been loaded.
each plugin has its own pytest_configure method, and what happens here is that your pytest_configure of you conftest.py is called before the pytest_configure of allure plugin.
An easy fix is to ask your pytest_configure to be executed as late as possible (preferable the last one) by adding @pytest.hookimpl(trylast=True) as header.
@pytest.hookimpl(trylast=True)
def pytest_configure(config):
allure.environment(test_server='testserver', report='My Test Report')
回答2:
As I discovered in the code realization of allure
setting environment variables is not implemented yet in the framework for Python.
allure.py
module.
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'
]
The developers of Allure are aware of that and are working on it. You can see the respective bug.
回答3:
You could set allure test environment data like this:
def pytest_sessionfinish(session, exitstatus):
session.config.allure.environment(test_server='testserver', report='My Test Report')
Old allure pytest plugin is deprecated and new allure pytest plugin is not feature compatible with old one.
If you want to add environment properties, you will have to create environment.properties
file and place it in alluredir folder.
def pytest_sessionfinish(session, exitstatus):
report_dir = session.config.option.allure_report_dir # Gets the --alluredir directory path
env_details = """a:b
c:d
"""
if report_dir:
with open('{}/{}'.format(report_dir, 'environment.properties'), 'w') as allure_env:
allure_env.write({}.format(env_details))
This code will create environment.properties
file and put it in allure results dir. When you serve that directory with allure-cli, you will see environment details.
回答4:
I never tried pytest adapter. But you convert XML report to HTML with the same tool whatever adapter is. So environment.properties should work. You can test it with https://github.com/allure-examples/allure-testng-example:
- mvn test
- create target/allure-results/environment.properties "testserver=My Test Report"
- mvn site
- open target/site/allure-maven-plugin/index.html in FireFox
If it doesn't, please check Allure version right in HTML report.
来源:https://stackoverflow.com/questions/35264335/customize-allure-report-using-pytest-allure-adaptor