1. 程式人生 > 其它 >【Python_pytest】pytest 實用外掛

【Python_pytest】pytest 實用外掛

 pytest 斷言

 原生 assert 

# 無需安裝
# 在斷言失敗時,會停止執行之後的程式碼或斷言。
assert 1 == 1, "不相等"

  

pytest-check 模組的斷言

# 會執行所有的測試用例,斷言失敗時,可自定義列印資訊,更利於記錄和排查問題。
pip install pytest-check  
pytest-check.equal("1",  "1", "錯誤原因:不相等")

 

多重斷言 pytest-assume

# 在斷言失敗時,不會停止執行程式碼,會執行所有的測試用例,但斷言失敗時的結果不詳細。
pip install pytest-assume  

 

 

 測試報告

pip install pytest-html

示例:  https://www.cnblogs.com/phoenixy/p/16144461.html 

 

元資料使用

pip install pytest-metadata     # 元資料使用

 

 

日期模組

pip install python-dateutil

 

 

控制用例的執行順序

pip install pytest-ordering 

 示例:  https://www.cnblogs.com/phoenixy/p/16143132.html


分散式併發執行測試用例

pip install pytest-xdist

 

 

控制用例的依賴關係 

pip install pytest-dependency 

 


失敗重跑

pip install pytest-rerunfailures 

 

 

用例隨機執行

pip install pytest-random-order