pytest生成html报告 -- pytest-html插件

pytest大保健系列

1.使用前提

  • Python3.6+

2.pip安装

pip3 install pytest-html -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

3.基本用法 直接上手

--html=report.html 
import pytest

@pytest.mark.repeat(2)
def test_case1():
    print("执行测试用例1")
    assert 1 + 1 == 2

def test_case2():
    print("执行测试用例2")
    assert 1 + 3 == 6
demo.py

运行:

pytest --html=report.html -s demo.py # 存放在同级文件夹下的report.html文件
pytest --html=./report/report.html -s demo.py # 存放在report文件夹的report.html文件
# 上面方法生成的报告,css是独立生成在./assets/style.css中,分享报告的时候样式会丢失,为了更好的分享展示报告,把css合并到html里 pytest --html=./report/report.html --self-contained-html -s demo.py

 

 

posted @ 2022-02-24 16:06  www.pu  Views(77)  Comments(0Edit  收藏  举报