pytest之html报告

html格式测试报告:
插件安装 pip install pytest-html

pytest可以生成多种样式的结果

1.生成junitXML 格式的测试报告:命令:–junitxml=path
xml文件作用 – 可以跟外部继承 或者 做二次解析
2.生成result log 格式的测试报告:命令:–resultlog=report\log.txt
3.生成html 格式的测试报告:命令:–html=report\test_one.html(相对路径)
路径:以pytest命令行所在的目录为根目录 - 开始收集测试用例 - 获取路径的
所谓的相对路径 - 就是相对于这个目录

第一种方式:

当前目录运行:
在这里插入图片描述
生成html测试报告:
pytest生成html报告

示例
在这里插入图片描述

第二种:(常用)

pytest.ini文件

[pytest]
markers =
    demo

conftest.py文件 – 放前置的地方/放用例当中也可以

import pytest

@pytest.fixture()
def init():
    print("我是函数级别前置")
    a = 1
    # yield a
    b = 2
    yield a, b
    print("我是函数别后置")


@pytest.fixture(scope="class")
def init1():
    print("我是类级别前置")
    c = 3
    d = 4
    yield c,d
    print("我是类级别后置")

test_demo文件

import pytest

pytestmark = pytest.mark.demo

@pytest.mark.usefixtures("init")  # 使用返回值,就不需要声明 -- 也可以声明不影响
def test_aaa(init):  # 使用返回值,就不需要声明 --会自动找init
    print("aaa")
    c = init[0] + 1
    print(c)

# 不用声明会自己找
class TestD:
    def test_ddd(self,init1):
        print("ddd")
        d = init1[1] + 1
        print(d)
        assert 6 == d

run文件

import pytest

pytest.main(["-s", "-v", "-m", "demo", "--html=Outputs/report.html",
             "--reruns", "2", "--reruns-delay", "5"])

–结果与上面一致

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值