pytest之生成測試報告


一、pytest-html生成報告

pytest-html的github源碼地址:https://github.com/pytest-dev/pytest-html

安裝:pip install pytest-html

1、在cmd中執行命令生成測試報告:

# 使用pytest-xdist多進程運行生成html測試報告,並指定報告生成位置

pytest -s -n=3 get_multithread.py --html=./report/xdist3.html

2、在PyCharm中執行命令生成測試報告:

# 使用pytest-parallel多線程運行生成測試報告,且將css樣式合並到html中

if __name__ == "__main__":
    pytest.main(['-s', '--tests-per-worker=3', '--html=xdist2.html', '--self-contained-html',  __file__])    

3、效果預覽

 

二、allure-pytest生成報告

# 安裝
pip install allure-pytest

# 安裝allure-command工具:
參考:https://www.cnblogs.com/yoyoketang/p/12004145.html
cmd命令行運行:
(1)E:\Temp>pytest -s -q  test_register.py --alluredir report(即path_to_report_dir)
(2)E:\Temp>allure generate --clean report 或 E:\Temp\allure generate report/ -o report/html --clean
再通過PyCharm打開生成的html文件
(打開html報告后,可點擊"EN"切換報告語言)

 

allure的常用功能特性:

1、@allure.feature():可以用來定制測試類標題,如:xxx模塊

2、@allure.story():可以用來定制函數方法標題,如:注冊成功,注冊失敗

3、@allure.step():用來描述測試步驟,如實例化對象

4、@allure.description():提供字符串內容描述,如用例描述...

5、@allure.title():用於描述用例的標題

6、@allure.link()、@allure.issure()、@allure.testcase():提供特定的鏈接url

7、allure.attach((body, name, attachment_type, extension):用於向報告中新增附加的信息

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

8、@allure.severity('critical'):用於描述用例的級別

blocker級別:中斷缺陷(客戶端程序無響應,無法執行下一步操作)

critical級別:臨界缺陷( 功能點缺失)

normal級別:普通缺陷(數值計算錯誤)

minor級別:次要缺陷(界面錯誤與UI需求不符)

trivial級別:輕微缺陷(必輸項無提示,或者提示不規范)

 

三、關於allure-pytest生成的報告直接用瀏覽器打開時一直顯示loading...

原因:存在跨域的問題

解決辦法:下載node,搭建anywhere靜態服務器

AnyWhere是一款隨啟隨用的靜態文件服務器,可以隨時隨地將你的當前目錄變成一個靜態文件服務器的根目錄。

 

 

參考:https://www.jianshu.com/p/3f0b7ea9df53

參考:http://www.manongjc.com/detail/12-bxyybsulsoplcyg.html

參考:https://blog.csdn.net/liuchunming033/article/details/79624474

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM