安装
pip install pytest-html
使用
测试代码:
import pytest
from random import randint
@pytest.mark.flaky(reruns=3)
def test01():
assert randint(1, 10) == 6
def test02():
assert randint(1, 10) > 6
def test03():
assert randint(1, 10) < 6
if __name__ == '__main__':
pytest.main(['pytestReport.py', '-s', "--html=report.html"])
命令行参数执行,加入--html=report.html
执行完毕后得到report.html
文件和assets
(包括html文件的css样式)文件夹。
打开report.html
文件即可看到测试报告:
命令行参数执行,加入--html=report.html --self-contained-html
参数。则生成的css文件和html文件集为一体,最终只生成一个html文件
测试报告汉化
因为测试报告目前都是英文版的,目前可以通过使用其他开源项目替换成生成中文版报告
地址: https://github.com/13691579846/pytest-html
在本地的python安装目录下, /site-packages/site-packages/下替换pytest-html
整个文件,然后再执行会发现已经替换为中文版的报告。