前言:pytest-HTML是一個插件,pytest用於生成測試結果的HTML報告。兼容Python 2.7,3.6
pytest-html
1. pip 安裝: pip install pytest-html
2. 執行方法: pytest (-q 指定py腳本文件) --html = report.html【目標html名稱,直接寫名稱是在當前目錄下,也可定義目錄下的文件夾:./ xx文件夾/ xx.html】
隨便找一個腳本執行實例看下:
好了,在demo1文件夾下可以找到report.html,打開就可以看到報告了:
3. 失敗重試
失敗重跑需要依賴pytest -rerunfailures插件,使用pip安裝即可。
pip安裝命令:pip install pytest-rerunfailures
執行命令:pytest xx.py --reruns 1 --html=report2.html --self-contained-html 【--self-contained-html加這個是為了生成的html文件自帶css樣式】
從報告可以看出,rerun 一次。