zoukankan      html  css  js  c++  java
  • 【pytest学习】pytest+allure生成定制化测试报告

    一、allure安装

    Windows电脑:下载allure压缩包解压,并将'安装路径'in加入到系统变量中,在cmd中输入allure --version有回显即安装成功

      下载地址:https://github.com/allure-framework/allure2/releases

    Mac电脑:brew install allure

    二、安装allure-pytest库

    可以在pycharm中安装,也可以使用命令pip install allure-pytest

    三、生成报告

    python -m pytest xxx.py -s -q --alluredir ./report/xml
    allure generate ./report/xml -o ./report/html

    四、报告查看

    直接打开index.html文件即可

    注⚠️:直接用chrome浏览器打开报告,报告可能会是空白页面。
    解决办法:
    1、在pycharm中右击index.html选择打开方式Open in Browser就可以了。
    2、使用Firefox直接打开index.html。

    五、allure其他定制

    • Feature: 标注主要功能模块
    • Story: 标注Features功能模块下的分支功能
    • Severity: 标注测试用例的重要级别
    • Step: 标注测试用例的重要步骤
    • Issue和TestCase: 标注Issue、Case,可加入URL

    【Allure中对严重级别的定义:
    1、 Blocker级别:中断缺陷(客户端程序无响应,无法执行下一步操作)
    2、 Critical级别:临界缺陷( 功能点缺失)
    3、 Normal级别:普通缺陷(数值计算错误)
    4、 Minor级别:次要缺陷(界面错误与UI需求不符)
    5、 Trivial级别:轻微缺陷(必输项无提示,或者提示不规范)】

    @allure.step("字符串相加:{0},{1}")     # 测试步骤,可通过format机制自动获取函数参数
    def str_add(str1, str2):
    print('hello')
    if not isinstance(str1, str):
    return "%s is not a string" % str1
    if not isinstance(str2, str):
    return "%s is not a string" % str2
    return str1 + str2

    @allure.feature('test_module_01')
    @allure.story('test_story_01')
    @allure.severity('blocker')
    @allure.issue("http://www.baidu.com")
    @allure.testcase("http://www.testlink.com")
    def test_case():
    str1 = 'hello'
    str2 = 'world'
    assert str_add(str1, str2) == 'helloworld'


    if __name__ == '__main__':
    pytest.main(['-s', '-q', '--alluredir', './report/xml'])

    六、attach定制

    在报告中增加附件:allure.attach(’arg1’,’arg2’,’arg3’):
    arg1:是在报告中显示的附件名称
    arg2:表示添加附件的内容
    arg3:表示添加的类型(支持:HTML,JPG,PNG,JSON,OTHER,TEXTXML)

    file = open('../test.png', 'rb').read()
    allure.attach('test_img', file, allure.attach_type.PNG)

    参考文档:

    https://www.cnblogs.com/xiaoxi-3-/p/9492534.html

  • 相关阅读:
    Django基础二之URL路由系统
    Django基础一之web框架的本质
    HTTP协议超级详解
    动态规划-背包问题
    java 中对象比较大小
    排序算法
    泛型
    打jar包和使用jar包
    Mongodb中Sharding集群
    linux时间同步,ntpd、ntpdate
  • 原文地址:https://www.cnblogs.com/ricebug2/p/14031164.html
Copyright © 2011-2022 走看看