pytest——生成HTML报告

在人生的道路上,不管是潇洒走一回,或者是千山独行,皆须是自己想走的路,虽然,有的人并不是很快就能找到自己的方向和道路,不过,只要坚持到底,我相信,就一定可以找到自己的路,只要找到路,就不必怕路途遥远了。

导读:本篇文章讲解 pytest——生成HTML报告,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

在这里插入图片描述


一.前言

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

在这里插入图片描述

测试报告

在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/123165.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!