小編寫這篇文章的主要目的,是給大家來(lái)做個(gè)介紹,介紹關(guān)于測(cè)試報(bào)告工具Allure用法的一些詳解,主要是關(guān)于一些Pytest Allure類的用法,那么,具體的代碼實(shí)例是什么呢?下面就給大家詳細(xì)解答下。
Allure除了具有Pytest基本狀態(tài)外,其他幾乎所有功能也都支持。
1、嚴(yán)重性
如果你想對(duì)測(cè)試用例進(jìn)行嚴(yán)重等級(jí)劃分,可以使用 allure.severity裝飾器,它可以應(yīng)用于函數(shù),方法或整個(gè)類。
它以allure.severity_level枚舉值作為參數(shù),分別為:BLOCKER(中斷),CRITICAL(嚴(yán)重),NORMAL(常規(guī)),MINOR(輕微),TRIVIAL(不重要)。
示例:
#test_sample.py import allure #兩數(shù)相加 def add(x,y): return x+y #測(cè)試類 allure.severity(allure.severity_level.TRIVIAL) class TestAdd: allure.severity(allure.severity_level.MINOR) def test_first(self): assert add(3,4)==7 allure.severity(allure.severity_level.NORMAL) def test_second(self): assert add(-3,4)==1 allure.severity(allure.severity_level.CRITICAL) def test_three(self): assert add(3,-4)==-1 allure.severity(allure.severity_level.BLOCKER) def test_four(self): assert add(-3,-4)==-7
運(yùn)行:
E:\workspace-py\Pytest>pytest test_sample.py--alluredir=report--clean-alluredir
==========================================================================test session starts==========================================================================
platform win32--Python 3.7.3,pytest-6.0.2,py-1.9.0,pluggy-0.13.0
rootdir:E:\workspace-py\Pytest
plugins:allure-pytest-2.8.18,assume-2.3.3,cov-2.10.1,html-3.0.0,rerunfailures-9.1.1,xdist-2.1.0
collected 4 items
test_sample.py....[100%]
===========================================================================4 passed in 0.06s===========================================================================
報(bào)告:
E:\workspace-py\Pytest>pytest test_sample.py--allure-severities normal,critical
==========================================================================test session starts==========================================================================
platform win32--Python 3.7.3,pytest-6.0.2,py-1.9.0,pluggy-0.13.0
rootdir:E:\workspace-py\Pytest
plugins:allure-pytest-2.8.18,assume-2.3.3,cov-2.10.1,html-3.0.0,rerunfailures-9.1.1,xdist-2.1.0
collected 4 items
test_sample.py..[100%]
===========================================================================2 passed in 0.02s===========================================================================
2、功能
如果你想對(duì)測(cè)試功能、測(cè)試場(chǎng)景進(jìn)行行為描述,可以分別使用裝飾器: allure.feature和 allure.story。
示例:
#test_sample.py import allure #兩數(shù)相加 def add(x,y): return x+y allure.feature('測(cè)試類') class TestAdd: allure.story('01測(cè)試兩個(gè)正數(shù)相加') def test_first(self): assert add(3,4)==7 allure.story('02測(cè)試負(fù)數(shù)正數(shù)相加') def test_second(self): assert add(-3,4)==1 allure.story('03測(cè)試正數(shù)負(fù)數(shù)相加') def test_three(self): assert add(3,-4)==-1 allure.story('04測(cè)試兩個(gè)負(fù)數(shù)相加') def test_four(self): assert add(-3,-4)==-7
運(yùn)行:
E:\workspace-py\Pytest>pytest test_sample.py--alluredir=report--clean-alluredir
==========================================================================test session starts==========================================================================
platform win32--Python 3.7.3,pytest-6.0.2,py-1.9.0,pluggy-0.13.0
rootdir:E:\workspace-py\Pytest
plugins:allure-pytest-2.8.18,assume-2.3.3,cov-2.10.1,html-3.0.0,rerunfailures-9.1.1,xdist-2.1.0
collected 4 items
test_sample.py....[100%]
===========================================================================4 passed in 0.06s===========================================================================
報(bào)告:
你也可以通過(guò)--allure-features和--allure-stories選擇指定具體功能和故事運(yùn)行,多個(gè)以逗號(hào)分隔。
E:\workspace-py\Pytest>pytest test_sample.py--allure-stories 01測(cè)試兩個(gè)正數(shù)相加
==========================================================================test session starts==========================================================================
platform win32--Python 3.7.3,pytest-6.0.2,py-1.9.0,pluggy-0.13.0
rootdir:E:\workspace-py\Pytest
plugins:allure-pytest-2.8.18,assume-2.3.3,cov-2.10.1,html-3.0.0,rerunfailures-9.1.1,xdist-2.1.0
collected 4 items
test_sample.py.[100%]
===========================================================================1 passed in 0.02s===========================================================================
3、步驟
如果你想對(duì)每個(gè)測(cè)試調(diào)用進(jìn)行非常詳細(xì)的逐步說(shuō)明,可以通過(guò) allure.step裝飾器來(lái)實(shí)現(xiàn)(固件同樣支持)。
該裝飾器會(huì)將方法或函數(shù)的調(diào)用與提供的參數(shù)一起添加到報(bào)表中,并且可以包含一條描述行,該行支持位置和關(guān)鍵字參數(shù)。
示例:
#test_sample.py import pytest import allure allure.step('兩數(shù)相加:{0}+{y}') def add(x,y): r=x+y print_res(r) return r allure.step def print_res(r): print('計(jì)算結(jié)果:',r) class TestLearning: data=[ [3,4,7], [-3,4,1], [3,-4,-1], [-3,-4,-7], ] pytest.mark.parametrize("data",data) def test_add(self,data): assert add(data[0],data[1])==data[2]
報(bào)告:
4、標(biāo)題
如果你想讓測(cè)試標(biāo)題更具可讀性,可以使用 allure.title裝飾器,該裝飾器支持參數(shù)的占位符并支持動(dòng)態(tài)替換。
示例:
#test_sample.py import pytest import allure def add(x,y): return x+y class TestLearning: data=[ [3,4,7], [-3,4,1], [3,-4,-1], [-3,-4,-7], ] allure.title("測(cè)試用例-{data}") pytest.mark.parametrize("data",data) def test_add(self,data): assert add(data[0],data[1])==data[2]
報(bào)告:
5、描述
如果你想添加測(cè)試的詳細(xì)說(shuō)明,可以通過(guò)添加測(cè)試方法描述信息,也可以使用裝飾器 allure.description和 allure.description_html。
示例:
#test_sample.py import allure #被測(cè)功能 def add(x,y): return x+y #測(cè)試類 class TestLearning: allure.description('測(cè)試正數(shù)相加') def test_first(self): assert add(3,4)==7 allure.description_html('<h1>測(cè)試負(fù)數(shù)相加</h1>') def test_second(self): """你也可以在這里添加用例的描述信息,但是會(huì)被allure裝飾器覆蓋""" assert add(-3,-4)==-7
報(bào)告:
6、附件
如果你想在報(bào)告中顯示不同類型的附件,可以通過(guò)以下兩種方式來(lái)實(shí)現(xiàn):
allure.attach(body,name,attachment_type,extension)
allure.attach.file(source,name,attachment_type,extension)
示例:
import allure def test_multiple_attachments(): allure.attach.file(r'C:\Users\Public\Pictures\Sample Pictures\Koala.jpg',attachment_type=allure.attachment_type.JPG) allure.attach('<head></head><body>測(cè)試頁(yè)面</body>','Attach with HTML type',allure.attachment_type.HTML)
報(bào)告:
7、鏈接
如果你想關(guān)聯(lián)缺陷追蹤系統(tǒng)或測(cè)試管理系統(tǒng),你可以使用裝飾器 allure.link、 allure.issue、 allure.testcase。
示例:
import allure allure.link('http://www.baidu.com') def test_with_named_link(): pass allure.issue('101','缺陷問(wèn)題描述') def test_with_issue_link(): pass allure.testcase('http://this.testcase.com','測(cè)試用例標(biāo)題') def test_with_testcase_link(): pass
報(bào)告:
注意:
allure.issue將提供帶有小錯(cuò)誤圖標(biāo)的鏈接,該描述符將測(cè)試用例ID作為輸入?yún)?shù),以將其與提供的問(wèn)題鏈接類型的鏈接模板一起使用。
鏈接模板在--allure-link-patternPytest的配置選項(xiàng)中指定。鏈接模板和類型必須使用冒號(hào)指定:
pytest test_sample.py--alluredir=report--allure-link-pattern=issue:http://www.mytesttracker.com/issue/{}
官方文檔地址:https://docs.qameta.io/allure/
綜上所述,就為大家介紹到這里了,希望可以為各位讀者帶來(lái)幫助。
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/128177.html
小編寫這篇文章的一個(gè)主要目的,主要是給大家介紹Python Pytest工具的介紹,主要是用來(lái)做測(cè)試報(bào)告工具用的,涵蓋的測(cè)試報(bào)告工具還是比較的多的,比如會(huì)使用到ALLure工具,具體怎么使用呢?下面就給大家詳細(xì)介紹下。 簡(jiǎn)介 Allure Framework是一種靈活的、輕量級(jí)、多語(yǔ)言測(cè)試報(bào)告工具?! 〔粌H可以以簡(jiǎn)潔的網(wǎng)絡(luò)報(bào)告形式非常簡(jiǎn)潔地顯示已測(cè)試的內(nèi)容, 而且還允許參與開(kāi)發(fā)過(guò)程的每個(gè)...
摘要:前端自動(dòng)化測(cè)試百度搜索功能實(shí)戰(zhàn)可以與結(jié)合生成測(cè)試報(bào)告。以網(wǎng)頁(yè)版本的百度為例,百度首頁(yè)呈現(xiàn)的功能新聞網(wǎng)頁(yè)貼吧知道音樂(lè)圖片視頻地圖等,我們以百度網(wǎng)頁(yè)的搜索功能為例,使用結(jié)合自動(dòng)化測(cè)試框架,完成一個(gè)搜索功能的測(cè)試。 ...
摘要:簡(jiǎn)介是一個(gè)很實(shí)用的客戶端庫(kù)編寫爬蟲(chóng)和測(cè)試服務(wù)器響應(yīng)數(shù)據(jù)時(shí)經(jīng)常會(huì)用到是語(yǔ)言的第三方的庫(kù)專門用于發(fā)送請(qǐng)求前提要下載請(qǐng)求無(wú)參數(shù)請(qǐng)求有參數(shù)請(qǐng)求案例傳參的第一種方式傳參的第二種方式請(qǐng)求類似中的表單提交 ...
摘要:?jiǎn)栴}大部分問(wèn)題是因?yàn)榘惭b了導(dǎo)致的比如此時(shí)需要先卸載然后再安裝包已經(jīng)安裝過(guò)的不用重復(fù)安裝。版本問(wèn)題類似于這種一般是因?yàn)榘姹咎邔?dǎo)致建議卸載現(xiàn)有版本并安裝較低版本的。后續(xù)重裝低版本出現(xiàn)如下報(bào)錯(cuò)重裝最新版本并重裝包 ...
摘要:根據(jù)具體的自動(dòng)化測(cè)試崗位來(lái)說(shuō)的,不要覺(jué)得自動(dòng)化測(cè)試是機(jī)構(gòu)炒起來(lái)的,確實(shí)有它存在的必要。自動(dòng)化測(cè)試是相對(duì)手工測(cè)試而存在的,主要是通過(guò)所開(kāi)發(fā)的軟件測(cè)試工具腳本等來(lái)實(shí)現(xiàn),具有良好的可操作性可重復(fù)性和高效率等特點(diǎn)。 當(dāng)代的打工人真的太苦了! 每個(gè)月拿著幾千塊的工資,卻為公司拼命,為老板賺錢; 天天9...
閱讀 1070·2023-01-14 11:38
閱讀 1067·2023-01-14 11:04
閱讀 907·2023-01-14 10:48
閱讀 2387·2023-01-14 10:34
閱讀 1152·2023-01-14 10:24
閱讀 1029·2023-01-14 10:18
閱讀 658·2023-01-14 10:09
閱讀 737·2023-01-14 10:02