allure报告定制(pytest+jenkins)

环境及安装可查看

pytest+jenkins安装+allure导出报告

要让allure报告更漂亮,更直观,需要在脚本中写入allure特性

一开始allure调用step()、story()、feature()等总是报错,提示不存在这些方法。

@allure.feature('ceshi')

警告信息:

通过查看allure的__init__.py文件

在调用allure的feature()、story()、step()等方法时,加上MASTER_HELPER即可

@allure.MASTER_HELPER.feature()
import allure
# @allure.environment(report='reports1', browser='chrome')

# @allure.feature('ceshi')  # 定义功能
@allure.MASTER_HELPER.feature('feature定义功能')  # 定义功能
class Testtest(object):
    # @allure.story('定义用户场景')
    @allure.MASTER_HELPER.story('story定义用户场景1')
    @allure.MASTER_HELPER.severity('blocker')
    @allure.MASTER_HELPER.issue("http://www.baidu.com")
    @allure.MASTER_HELPER.testcase("http://www.testlink.com")
    def test_add(self):  # 调用步骤函数
        """
        用例描述:这是测试用例描述
        """
        print('调用步骤函数')
        file = open('E:/py/20190411144914.PNG','rb').read()
        allure.MASTER_HELPER.attach('test_img', file, allure.MASTER_HELPER.attach_type.PNG)
        assert add(1, 1) == 2

    # @allure.story('定义用户场景2')
    @allure.MASTER_HELPER.story('story定义用户场景2')
    @allure.MASTER_HELPER.severity('Critical')
    def test_minus(self):
        assert minus(2, 1) == 2

    # @allure.story('定义用户场景3')
    @allure.MASTER_HELPER.story('story定义用户场景3')
    @allure.MASTER_HELPER.severity('Minor')
    def test_aa(self):
        print("123")

    # @allure.story('定义用户场景4')
    @allure.MASTER_HELPER.story('story定义用户场景4')
    @allure.MASTER_HELPER.severity('Critical')
    def test_bb(self):
        assert add(1, 1) > minus(2, 1)

    @allure.MASTER_HELPER.story('story定义用户场景5')
    @allure.MASTER_HELPER.severity('Minor')
    def test_cc(self):
        print("abc!")

# @allure.step('测试123!')  # 步骤函数
@allure.MASTER_HELPER.step('step字符串相加:{0},{1}')
def add(a, b):
    return a + b

@allure.MASTER_HELPER.step('step字符串相减:{0},{1}!')
def minus(c, d):
    return c - d

立即构建后:

说明:

Severity定制详解

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

attach定制详解

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

 file = open('E:/py/20190411144914.PNG','rb').read()
 allure.MASTER_HELPER.attach('test_img', file, allure.MASTER_HELPER.attach_type.PNG)

 ----------------------------------------------------------

-----------------------------------------------------------

若运行后报错如下:

INTERNALERROR> _pytest.warning_types.RemovedInPytest4Warning: MarkInfo objects are deprecated as they contain merged marks which are hard to deal with correctly.
INTERNALERROR> Please use node.get_closest_marker(name) or node.iter_markers(name).
INTERNALERROR> Docs: https://docs.pytest.org/en/latest/mark.html#updating-code

这个是运行警告,解决办法如下:


1.命令行运行:添加参数-p no:warnings

运行后就没有上面的警告信息了

2.配置pytest.ini

[pytest]
addopts = -p no:warnings

 -p no: 命令是禁用插件扩展

方法:

新建一个配置文件pytest.ini,存放在测试目录中

原文地址:https://www.cnblogs.com/may18/p/10678642.html