allure定製化輸出測試報告-詳解

前言:之前文章( )已經介紹了環境搭建,本篇具體介紹一下allure的一些相關特性

環境:Windows 10、SublimeText3、Python3、pytest、allure

一、先看效果圖(可以切換成中文模式)


allure定製化輸出測試報告-詳解


allure定製化輸出測試報告-詳解


二、allure定製化內容特性詳解

使用前必須先引入模塊:import allure

1、feature(主要功能模塊--一級標籤)

使用方法:@allure.feature()

2、story(子功能模塊--二級標籤)

使用方法:@allure.story()

3、title(測試用例標題)

使用方法: @allure.title

4、description(測試用例描述)

使用方法:@allure.description()

5、step(測試用例步驟)

使用方法:@allure.step()

6、severity(BUG嚴重級別)

1)使用方法:@allure.severity(allure.severity_level.CRITICAL)

或者 @allure.severity('critical')

2)相關說明: Allure中對嚴重級別的定義:

  • blocker級別:中斷缺陷(客戶端程序無響應,無法執行下一步操作)
  • critical級別:臨界缺陷( 功能點缺失)
  • normal級別:普通缺陷(數值計算錯誤)
  • minor級別:次要缺陷(界面錯誤與UI需求不符)
  • trivial級別:輕微缺陷(必輸項無提示,或者提示不規範)

7、link/issue/testcase(鏈接)

使用方法:

@allure.link(url='http://www.baidu.com',name='link_url')

@allure.issue(url='http://www.baidu.com',name='issue_url') #bug鏈接

@allure.testcase(url='http://www.tapd.com',name='testcase_url')

8、.attach(附件信息)

使用方法:@allure.attach(body, name, attachment_type, extension)

  • body - 要寫入文件的原始內容
  • name - 包含文件名的字符串
  • attachment_type - 其中一個allure.attachment_type值
  • extension - 提供的將用作創建文件的擴展名

9、代碼如下:

<code>import pytest
import allure

class TestAllure():
@allure.feature('一級標籤')
@allure.story("二級標籤")
@allure.title("測試用例標題")
@allure.description("測試用例描述")
@allure.step("測試用例步驟")
@allure.severity(allure.severity_level.CRITICAL) #測試用例級別
@allure.link(url='http://www.baidu.com',name='link_url')
@allure.issue(url='http://www.baidu.com',name='issue_url') #bug鏈接
@allure.testcase(url='http://www.tapd.com',name='testcase_url')
def test_1(self):
#測試用例附件信息
with open('C:\\\\Users\\zzp\\\\Desktop\\\\pytest\\\\tea.png','rb') as f:
file=f.read()
allure.attach(file,'picture',allure.attachment_type.PNG)
assert 1>2
def test_2(self):
pass

if __name__ == '__main__':

pytest.main(["-s","test_01.py",'-q','--alluredir','./report'])/<code>


allure定製化輸出測試報告-詳解


allure定製化輸出測試報告-詳解


allure定製化輸出測試報告-詳解


分享到:


相關文章: