使用 pytest-allure-adaptor 自定义 Allure 报告 [英] Customize Allure Report using pytest-allure-adaptor

查看:124
本文介绍了使用 pytest-allure-adaptor 自定义 Allure 报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 pytest 适配器 自定义我的诱惑测试报告.例如,在概览页面上添加环境详细信息.更改概览屏幕上的报告名称.

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.

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

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')

我也尝试在 allure-report 文件夹中添加 environment.properties 但这也不起作用.如果我在这里做错了什么,请告诉我,我该如何解决这个问题.

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.

推荐答案

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

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')

旧的 allure pytest 插件已弃用,新的​​ allure pytest 插件与旧插件的功能不兼容.

Old allure pytest plugin is deprecated and new allure pytest plugin is not feature compatible with old one.

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

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))

此代码将创建 environment.properties 文件并将其放入 allure results 目录.当您使用 allure-cli 提供该目录时,您将看到环境详细信息.

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.

这篇关于使用 pytest-allure-adaptor 自定义 Allure 报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆