<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Pytest之重運(yùn)行及生成測試報(bào)告

          共 8801字,需瀏覽 18分鐘

           ·

          2020-09-10 00:32

          VOL 156

          09

          2020-09

          今天距2021年113天

          這是ITester軟件測試小棧第156次推文

          點(diǎn)擊上方藍(lán)字“ITester軟件測試小棧“關(guān)注我,每周一、、五早上 08:30準(zhǔn)時推送,每月不定期贈送技術(shù)書籍。


          微信公眾號后臺回復(fù)“資源測試工具包”領(lǐng)取測試資源,回復(fù)“微信群”一起進(jìn)群打怪。


          本文2124字,閱讀約需6分鐘





          在上一篇Pytest系列文章:Pytest之參數(shù)化,主要介紹pytest參數(shù)化講解及實(shí)戰(zhàn)。

          以下主要介紹Pytest的重運(yùn)行及生成測試報(bào)告。



          重運(yùn)行


          在做UI自動化,如Selenuim或者Appium時,遇到某些元素未能及時顯示,導(dǎo)致點(diǎn)擊失敗,如果加上重跑,那么將有效提高報(bào)告的準(zhǔn)確性。


          在Pytest中,可以使用pytest-rerunfailures用來失敗用例重跑。



          1

          安裝pytest-rerunfailures

          安裝命令:

          pip install pytest-rerunfailures



          2

          使用說明

          @pytest.mark.flaky(reruns=重試次數(shù), reruns_delay=次數(shù)之間的延時設(shè)置(單位:秒))



          3

          舉個栗子

          重試次數(shù)
          test_demo.py
          import pytest
          @pytest.mark.flaky(reruns=2)
          def test_demo():
              assert 3 == 4

          運(yùn)行結(jié)果為:

          指定重運(yùn)行等待時間:
          import pytest
          @pytest.mark.flaky(reruns=2,reruns_delay=2)
          def test_demo():
              assert 3 == 4

          運(yùn)行結(jié)果為:



          生成測試報(bào)告



          1

          pytest-html生成報(bào)告


          pytest使用pytest-html插件生成測試報(bào)告。


          ① 安裝pytest-html

          安裝命令:

          pip install pytest-html


          ② 舉個栗子


          現(xiàn)有用例如下:

          test_demo.py

          import pytest

          @pytest.mark.flaky(reruns=2,reruns_delay=2)
          def test_demo():
              assert 3 == 4

          test_demo1.py
          class TestDemo:
              def test_demo01(self):
                  print("這是test_demo01")
              def test_demo02(self):
                  print("這是test_demo02")

          命令行輸入:pytest --html=report.html

          運(yùn)行之后,會生成report.html,用瀏覽器打開report.html,如下:



          2

          allure生成報(bào)告

          用pytest-html生成的報(bào)告稍微簡單和丑了一點(diǎn),我們可以使用更強(qiáng)大的工具allureallure測試報(bào)告框架幫助你輕松實(shí)現(xiàn)"高大上"報(bào)告展示。


          01 安裝allure


          ①從github上下載allure,下載傳送門為:

          https://github.com/allure-framework/allure2/releases


          如下所示,選擇”Download“下載即可:


          ② 下載完后,解壓到項(xiàng)目根目錄下。


          ③ 安裝allure插件

          安裝命令:

          pip install allure-pytest

          ④ 添加環(huán)境變量:將allure-2.13.5\bin的目錄路徑添加到環(huán)境變量。



          02 舉個栗子


          ① 現(xiàn)有用例如下:

          test_demo.py

          import pytest

          @pytest.mark.flaky(reruns=2,reruns_delay=2)
          def test_demo():
              assert 3 == 4

          test_demo1.py
          class TestDemo:
              def test_demo01(self):
                  print("這是test_demo01")
              def test_demo02(self):
                  print("這是test_demo02")

          ② 在項(xiàng)目根目錄下新建目錄report。


          ③ 在命令行輸入:pytest -s -q --alluredir ./report在report目錄下會生成一些json格式的。


           在report目錄下,新建目錄html,用于存放html報(bào)告。


          ⑤ 命令行輸入allure generate ./report -o ./report/html,生成了最終的html報(bào)告。


          用瀏覽器打開index.html文件,效果如下:



          以上

          That‘s all
          更多系列文章
          敬請期待

          ITester軟件測試小棧
          往期內(nèi)容寵幸


          1.Python接口自動化-接口基礎(chǔ)(一)

          2.Python接口自動化-接口基礎(chǔ)(二)


          3.Python接口自動化-requests模塊之get請求


          4.Python接口自動化-requests模塊之post請求

          5.Python接口自動化之cookie、session應(yīng)用


          6.Python接口自動化之Token詳解及應(yīng)用


          7.Python接口自動化之requests請求封裝


          8.Python接口自動化之pymysql數(shù)據(jù)庫操作


          9.Python接口自動化之logging日志


          10.Python接口自動化之logging封裝及實(shí)戰(zhàn)

          想獲取更多最新干貨內(nèi)容
          快來星標(biāo) 置頂 關(guān)注
          每周一、三、五 08:30見

          <<  滑動查看下一張圖片  >>


           后臺 回復(fù)"資源"取干貨
          回復(fù)"微信群"一起打怪升級

          個人微信:Cc2015123  

          添加請注明來意 :)



          真愛三連,BiuBiuBiu~
          瀏覽 82
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  天天操夜操 | 免费观看A V | 免费A在线看 | 欧美色图亚洲图片插菊花综合 | 免费手机av |