pytest+allure如今都是结合jenkins来弄
定制报告
Feature: 标注主要功能模块
Story: 标注Features功能模块下的分支功能
Severity: 标注测试用例的重要级别
Step: 标注测试用例的重要步骤
Issue和TestCase: 标注Issue、Case,可加入URL
一、Features定制详解
# -*- coding: utf-8 -*-
# @Time : 2018/8/17 上午10:10
# @Author : WangJuan
# @File : test_case.py
import allure
import pytest
@allure.feature('test_module_01')
def test_case_01():
"""
用例描述:Test case 01
"""
assert 0
@allure.feature('test_module_02')
def test_case_02():
"""
用例描述:Test case 02
"""
assert 0 == 0
if __name__ == '__main__':
pytest.main(['-s', '-q', '--alluredir', './report/xml'])
添加feature,Report展现见下图。
二、Story定制详解
# -*- coding: utf-8 -*-
# @Time : 2018/8/17 上午10:10
# @Author : WangJuan
# @File : test_case.py
import allure
import pytest
@allure.feature('test_module_01')
@allure.story('test_story_01')
def test_case_01():
"""
用例描述:Test case 01
"""
assert 0
@allure.feature('test_module_01')
@allure.story('test_story_02')
def test_case_02():
"""
用例描述:Test case 02
"""
assert 0 == 0
if __name__ == '__main__':
pytest.main(['-s', '-q', '--alluredir', './report/xml'])
添加story,Report展现见下图。
三、用例标题和用例描述定制详解
# -*- coding: utf-8 -*-
# @Time : 2018/8/17 上午10:10
# @Author : WangJuan
# @File : test_case.py
import allure
import pytest
@allure.feature('test_module_01')
@allure.story('test_story_01')
#test_case_01为用例title
def test_case_01():
"""
用例描述:这是用例描述,Test case 01,描述本人
"""
#注释为用例描述
assert 0
if __name__ == '__main__':
pytest.main(['-s', '-q', '--alluredir', './report/xml'])
添加用例标题和用例描述,Report展现见下图。
4 、Severity定制详解
Allure中对严重级别的定义:
一、 Blocker级别:中断缺陷(客户端程序无响应,没法执行下一步操做)
二、 Critical级别:临界缺陷( 功能点缺失)
三、 Normal级别:普通缺陷(数值计算错误)
四、 Minor级别:次要缺陷(界面错误与UI需求不符)
五、 Trivial级别:轻微缺陷(必输项无提示,或者提示不规范)
# -*- coding: utf-8 -*-
# @Time : 2018/8/17 上午10:10
# @Author : WangJuan
# @File : test_case.py
import allure
import pytest
@allure.feature('test_module_01')
@allure.story('test_story_01')
@allure.severity('blocker')
def test_case_01():
"""
用例描述:Test case 01
"""
assert 0
@allure.feature('test_module_01')
@allure.story('test_story_01')
@allure.severity('critical')
def test_case_02():
"""
用例描述:Test case 02
"""
assert 0 == 0
@allure.feature('test_module_01')
@allure.story('test_story_02')
@allure.severity('normal')
def test_case_03():
"""
用例描述:Test case 03
"""
assert 0
@allure.feature('test_module_01')
@allure.story('test_story_02')
@allure.severity('minor')
def test_case_04():
"""
用例描述:Test case 04
"""
assert 0 == 0
if __name__ == '__main__':
pytest.main(['-s', '-q', '--alluredir', './report/xml'])
添加Severity,Report展现见下图。
五、Step定制详解
# -*- coding: utf-8 -*-
# @Time : 2018/8/17 上午10:10
# @Author : WangJuan
# @File : test_case.py
import allure
import pytest
@allure.step("字符串相加:{0},{1}")
# 测试步骤,可经过format机制自动获取函数参数
def str_add(str1, str2):
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')
def test_case():
str1 = 'hello'
str2 = 'world'
assert str_add(str1, str2) == 'helloworld'
if __name__ == '__main__':
pytest.main(['-s', '-q', '--alluredir', './report/xml'])
添加Step,Report展现见下图。
六、Issue和TestCase定制详解
# -*- coding: utf-8 -*-
# @Time : 2018/8/17 上午10:10
# @Author : WangJuan
# @File : test_case.py
import allure
import pytest
@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'])
添加Issue和TestCase,Report展现见下图。
八、attach定制详解
file = open('../test.png', 'rb').read()
allure.attach('test_img', file, allure.attach_type.PNG)
在报告中增长附件:allure.attach(’arg1’,’arg2’,’arg3’):
arg1:是在报告中显示的附件名称
arg2:表示添加附件的内容
arg3:表示添加的类型(支持:HTML,JPG,PNG,JSON,OTHER,TEXTXML)
添加attach参数,Report展现见下图。