成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Pytest測試報(bào)告工具Allure的高級用法

89542767 / 500人閱讀

    小編寫這篇文章的主要目的,是給大家來做個(gè)介紹,介紹關(guān)于測試報(bào)告工具Allure用法的一些詳解,主要是關(guān)于一些Pytest Allure類的用法,那么,具體的代碼實(shí)例是什么呢?下面就給大家詳細(xì)解答下。


  Allure除了具有Pytest基本狀態(tài)外,其他幾乎所有功能也都支持。


  1、嚴(yán)重性


  如果你想對測試用例進(jìn)行嚴(yán)重等級劃分,可以使用 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
  #測試類
   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)告:

01.png

  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、功能


  如果你想對測試功能、測試場景進(jìn)行行為描述,可以分別使用裝飾器: allure.feature和 allure.story。


  示例:


  #test_sample.py
  import allure
  #兩數(shù)相加
  def add(x,y):
  return x+y
   allure.feature('測試類')
  class TestAdd:
   allure.story('01測試兩個(gè)正數(shù)相加')
  def test_first(self):
  assert add(3,4)==7
   allure.story('02測試負(fù)數(shù)正數(shù)相加')
  def test_second(self):
  assert add(-3,4)==1
   allure.story('03測試正數(shù)負(fù)數(shù)相加')
  def test_three(self):
  assert add(3,-4)==-1
   allure.story('04測試兩個(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)告:

02.png

  你也可以通過--allure-features和--allure-stories選擇指定具體功能和故事運(yùn)行,多個(gè)以逗號分隔。


  E:\workspace-py\Pytest>pytest test_sample.py--allure-stories 01測試兩個(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、步驟


  如果你想對每個(gè)測試調(diào)用進(jìn)行非常詳細(xì)的逐步說明,可以通過 allure.step裝飾器來實(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)告:

03.png

  4、標(biāo)題


  如果你想讓測試標(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("測試用例-{data}")
   pytest.mark.parametrize("data",data)
  def test_add(self,data):
  assert add(data[0],data[1])==data[2]


  報(bào)告:

04.png

  5、描述


  如果你想添加測試的詳細(xì)說明,可以通過添加測試方法描述信息,也可以使用裝飾器 allure.description和 allure.description_html。


  示例:


  #test_sample.py
  import allure
  #被測功能
  def add(x,y):
  return x+y
  #測試類
  class TestLearning:
   allure.description('測試正數(shù)相加')
  def test_first(self):
  assert add(3,4)==7
   allure.description_html('<h1>測試負(fù)數(shù)相加</h1>')
  def test_second(self):
  """你也可以在這里添加用例的描述信息,但是會(huì)被allure裝飾器覆蓋"""
  assert add(-3,-4)==-7

  報(bào)告:

05.png

  6、附件


  如果你想在報(bào)告中顯示不同類型的附件,可以通過以下兩種方式來實(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>測試頁面</body>','Attach with HTML type',allure.attachment_type.HTML)


  報(bào)告:

06.png

  7、鏈接


  如果你想關(guān)聯(lián)缺陷追蹤系統(tǒng)或測試管理系統(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','缺陷問題描述')
  def test_with_issue_link():
  pass
   allure.testcase('http://this.testcase.com','測試用例標(biāo)題')
  def test_with_testcase_link():
  pass

  報(bào)告:

08.png

  注意:


   allure.issue將提供帶有小錯(cuò)誤圖標(biāo)的鏈接,該描述符將測試用例ID作為輸入?yún)?shù),以將其與提供的問題鏈接類型的鏈接模板一起使用。


  鏈接模板在--allure-link-patternPytest的配置選項(xiàng)中指定。鏈接模板和類型必須使用冒號指定:


  pytest test_sample.py--alluredir=report--allure-link-pattern=issue:http://www.mytesttracker.com/issue/{}


  官方文檔地址:https://docs.qameta.io/allure/


  綜上所述,就為大家介紹到這里了,希望可以為各位讀者帶來幫助。

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/128177.html

相關(guān)文章

  • Pytest測試報(bào)告工具Allure用法介紹

      小編寫這篇文章的一個(gè)主要目的,主要是給大家介紹Python Pytest工具的介紹,主要是用來做測試報(bào)告工具用的,涵蓋的測試報(bào)告工具還是比較的多的,比如會(huì)使用到ALLure工具,具體怎么使用呢?下面就給大家詳細(xì)介紹下?! 『喗椤 llure Framework是一種靈活的、輕量級、多語言測試報(bào)告工具?! 〔粌H可以以簡潔的網(wǎng)絡(luò)報(bào)告形式非常簡潔地顯示已測試的內(nèi)容,  而且還允許參與開發(fā)過程的每個(gè)...

    89542767 評論0 收藏0
  • 做完自動(dòng)化測試,但別讓不會(huì)匯報(bào)毀了你...

    摘要:前端自動(dòng)化測試百度搜索功能實(shí)戰(zhàn)可以與結(jié)合生成測試報(bào)告。以網(wǎng)頁版本的百度為例,百度首頁呈現(xiàn)的功能新聞網(wǎng)頁貼吧知道音樂圖片視頻地圖等,我們以百度網(wǎng)頁的搜索功能為例,使用結(jié)合自動(dòng)化測試框架,完成一個(gè)搜索功能的測試。 ...

    HelKyle 評論0 收藏0
  • Python接口測試之requests

    摘要:簡介是一個(gè)很實(shí)用的客戶端庫編寫爬蟲和測試服務(wù)器響應(yīng)數(shù)據(jù)時(shí)經(jīng)常會(huì)用到是語言的第三方的庫專門用于發(fā)送請求前提要下載請求無參數(shù)請求有參數(shù)請求案例傳參的第一種方式傳參的第二種方式請求類似中的表單提交 ...

    番茄西紅柿 評論0 收藏2637
  • Pytest+Allure使用問題記錄

    摘要:問題大部分問題是因?yàn)榘惭b了導(dǎo)致的比如此時(shí)需要先卸載然后再安裝包已經(jīng)安裝過的不用重復(fù)安裝。版本問題類似于這種一般是因?yàn)榘姹咎邔?dǎo)致建議卸載現(xiàn)有版本并安裝較低版本的。后續(xù)重裝低版本出現(xiàn)如下報(bào)錯(cuò)重裝最新版本并重裝包 ...

    番茄西紅柿 評論0 收藏2637
  • 就因?yàn)镻ython自動(dòng)化,那個(gè)天天摸魚同事,他居然升職了!

    摘要:根據(jù)具體的自動(dòng)化測試崗位來說的,不要覺得自動(dòng)化測試是機(jī)構(gòu)炒起來的,確實(shí)有它存在的必要。自動(dòng)化測試是相對手工測試而存在的,主要是通過所開發(fā)的軟件測試工具腳本等來實(shí)現(xiàn),具有良好的可操作性可重復(fù)性和高效率等特點(diǎn)。 當(dāng)代的打工人真的太苦了! 每個(gè)月拿著幾千塊的工資,卻為公司拼命,為老板賺錢; 天天9...

    laznrbfe 評論0 收藏0

發(fā)表評論

0條評論

最新活動(dòng)
閱讀需要支付1元查看
<