(allure报告定制)代码使用详解

1.allure常用方法:

2.@allure.severity用例的严重程度级别

blocker :中断缺陷、致命bug、数据丢失、系统奔溃。

critical:临界缺陷、严重bug功能为实现、功能错误、重复提交

normal:一般缺陷bug、条件查询有误、无响应

minor:次要用例级别,提示bug、颜色样式、字体排列错别字

trivial:轻微级别,轻微bug,必填项无提示。

3.allure.attach()添加附件

1)Allure报告中添加附件(html)

  • 语法:allure.attach(body, name, attachment_type, extension),参数解释:
    • body:要写入附件的内容(HTML 代码块)。
    • name:附件名字。
    • attachment_type:附件类型,是 allure.attachment_type 其中的一种。
    • extension:附件的扩展名。
  • allure.attach("""
                    <a href="/" data-auto-route="true"><img src="https://ceshiren.com/uploads/default/original/1X/809c63f904a37bc0c6f029bbaf4903c27f03ea8a.png" alt="测试人社区" id="site-logo" class="logo-big"></a>""",
                          name="添加html片段", attachment_type=allure.attachment_type.HTML, extension="html")
    allure.attach('''html代码块''', '附件是HTML类型', allure.attachment_type.HTML)

2)Allure报告中添加图片/视频附件

    • 语法:allure.attach.file(source, name, attachment_type, extension),参数解释:
      • source:文件路径,相当于传一个文件。
      • name:附件名字。
      • attachment_type:附件类型,是 allure.attachment_type 其中的一种。
      • extension:附件的扩展名。
allure.attach.file("/Users/may/Downloads/zz.jpg", name="截图name", attachment_type=allure.attachment_type.JPG, extension="jpg")

4. allure.title()测试用例标题

运行结果中,title标题会显示在story下方

5. 完整例子: 

import allure


@allure.epic('项目名称00,epic')
@allure.feature('测试模块,feature')  # 一般用在类上方
class TestAllureReport:
    @allure.title('测试用例标题00,title')
    @allure.story('测试成功,story')
    @allure.severity(allure.severity_level.CRITICAL)
    @allure.description('用例的描述,description')
    @allure.issue("输入缺陷管理系统的链接", name='bug链接issue')
    @allure.link("设置一个链接", name='链接名称link')
    @allure.testcase(url='测试用例地址', name='testcase测试用例name')
    def test_example(self):

        with allure.step("步骤1:执行某个操作"):
            # 这里执行某个操作,例如:
            result = 1 + 1

        with allure.step("步骤2:验证结果"):
            assert result == 2, "验证失败"

        allure.attach("""
                <a href="/" data-auto-route="true"><img src="https://ceshiren.com/uploads/default/original/1X/809c63f904a37bc0c6f029bbaf4903c27f03ea8a.png" alt="测试人社区" id="site-logo" class="logo-big"></a>""",
                      name="添加html片段", attachment_type=allure.attachment_type.HTML, extension="html")
        allure.attach('''html代码块''',
                      '附件是HTML类型',
                      allure.attachment_type.HTML)

        allure.attach.file("/Users/may/Downloads/zz.jpg", name="截图name", attachment_type=allure.attachment_type.JPG, extension="jpg")

主函数

# run.py
import pytest
import os


if __name__ == "__main__":
    pytest.main(["-s","./","--capture=sys"])   #--capture=sys会把报错的情况写进测试报告中
    os.system('allure generate report/result -o report/allure_html --clean')

6. 运行结果:

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值