pytest扫盲20--HTML报告

插件:pytest-html

github源码: https://github.com/pytest-dev/pytest-html

安装:

pip install pytest-html -i https://pypi.tuna.tsinghua.edu.cn/simple

执行:

  命令行执行:  pytest --html=report/test.html

  独立显示(发送html报告后,CSS样式不会丢失):  pytest --html=report/test.html --self-contained-html

  失败重运行:  pytest --reruns 2 --reruns-delay 2 --html=report/test.html --self-contained-html

  生成xml格式报告:  pytest --reruns 2 --reruns-delay 2 --html=report/test.html --junitxml=path --self-contained-html

  生成日志格式报告:    pytest --reruns 2 --reruns-delay 2 --html=report/test.html --junitxml=path --resultlog=reportlog.txt --self-contained-html  

示例1(不加 --self-contained-html):

pytest.main(['-s', '-q', '--reruns=2', '--reruns-delay=2', '--html=./report/report.html',  'test_demo_13_assert.py'])  

运行后生成带css的报告:

 示例2(html报告和CSS合并,独立显示):

pytest.main(['-s', '-q', '--reruns=2', '--reruns-delay=2', '--html=./report/report.html', '--self-contained-html', 'test_demo_13_assert.py'])  

运行后独立显示:

报告详情(duration持续时间,接口测试时可以分析接口响应时间)

原文地址:https://www.cnblogs.com/xiaohuboke/p/13569358.html