pytest——生成HTML报告

在这里插入图片描述


一.前言

pytest-html可以为pytest生成一个显示测试结果的网页。这个HTML报告可以对测试结果(通过,跳过,失败,错误,预期失败,预期失败但通过)进行筛选,还可以按测试名称,持续时间,结果状态来排序。HTML报告还可以定制一些元素,如数据集的截图等

二.使用

安装:

pip install pytest-html==2.1.0

目录结构

在这里插入图片描述

test_menus1.py

# encoding=utf-8
import pytest
import logging
import random
import time

@pytest.mark.smoke
class TestMenus:

    @pytest.mark.skipif(24<8,reason='版本不匹配')
    @pytest.mark.smoke
    def test_menu1(self):
        logging.info('执行测试用例1')
        assert 2 == 2

    #@pytest.mark.repeat(2)
    @pytest.mark.smoke
    def test_menu2(self):
        logging.info('执行测试用例2')
        assert 1 == 1

    def test_menu3(self):
        logging.info('执行测试用例3')
        assert 2 == 2


if __name__ == '__main__':
    pytest.main()

test_work1.py

#encoding=utf-8

import pytest

#@pytest.mark.skip()
class TestWork:

    @pytest.mark.smoke
    def test_h(self,home_url):
        print("用例:%s" % home_url)

    @pytest.mark.skipif(8<24,reason='版本不匹配')
    def test_work1(self):
        assert 1 == 1

    def test_work2(self):
        assert 1 == 1


if __name__ == '__main__':
    pytest.main()

执行命令

D:\project_development\api_pytest>pytest --html=./reports/test.html

在这里插入图片描述

测试报告

在这里插入图片描述

  • 8
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

敲代码敲到头发茂密

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值