首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用pytest- Allure -adaptor自定义allure报告

使用pytest- Allure -adaptor自定义allure报告
EN

Stack Overflow用户
提问于 2016-02-08 15:28:05
回答 4查看 4.3K关注 0票数 2

我想使用pytest adaptor自定义我的诱惑力测试报告。例如,在概述页上添加环境详细信息。在概述屏幕上更改报告名称。

我尝试按照文档中的建议在conftest.py中添加环境详细信息,但对我不起作用

代码语言:javascript
复制
def pytest_configure(config):
    allure.environment(test_server='testserver', report='My Test Report')

我还尝试将environment.properties添加到魅力报告文件夹中,但同样不起作用。如果我做错了什么,请让我知道,我如何解决这个问题。

EN

回答 4

Stack Overflow用户

发布于 2017-03-10 19:21:41

正如文档中所说的,迟到总比不到好。pytest_configure是

在解析命令行选项并加载所有插件和初始配置测试文件后调用

每个插件都有自己的pytest_configure方法,这里发生的事情是,您的pytest_configure of you conftest.py在调用魅力插件的pytest_configure之前被调用。

一个简单的解决方法是通过添加@pytest.hookimpl(trylast=True)作为头文件,要求pytest_configure尽可能晚地执行(最好是最后一个)。

代码语言:javascript
复制
@pytest.hookimpl(trylast=True)
def pytest_configure(config):
    allure.environment(test_server='testserver', report='My Test Report')
票数 1
EN

Stack Overflow用户

发布于 2017-08-23 20:12:28

正如我在allure的代码中发现的那样,设置环境变量还没有在Python框架中实现。allure.py模块。

代码语言:javascript
复制
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'
]

Allure的开发人员已经意识到了这一点,并正在努力。您可以看到相应的bug

票数 1
EN

Stack Overflow用户

发布于 2019-06-06 22:40:21

您可以像这样设置诱惑测试环境数据:

代码语言:javascript
复制
def pytest_sessionfinish(session, exitstatus):

    session.config.allure.environment(test_server='testserver', report='My Test Report')

旧的魅力pytest插件已弃用,新的魅力pytest插件与旧插件的功能不兼容。

如果您想要添加环境属性,则必须创建environment.properties文件并将其放置在alluredir文件夹中。

代码语言:javascript
复制
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))

这段代码将创建environment.properties文件,并将其放入引诱结果目录中。当您使用allure-cli提供该目录时,您将看到环境详细信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35264335

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档