pytest 插件

pytest 测试报告

安装

pip install pytest-html

使用

配置文件中添加参数addopts = -s --html=report/report.html

结果

在项目目录下会对一个 report 文件夹,里面有个 report.html 即为测试报告

 

 控制用例执行顺序

安装

pip install pytest-ordering

使用

  1. 标记于被测试函数,@pytest.mark.run(order=x)
  2. 根据order传入的参数来解决运行顺序
  3. order值全为正数或全为负数时,运行顺序:值越小,优先级越高
  4. 正负数同时存在:正数优先级高

测试代码

import pytest


def add(x, y):
    return x + y


class TestAdd:
    @pytest.mark.last  # 设置用例最后执行
    def test_add_01(self):
        result = add(1, 2)
        assert 3 == result

    @pytest.mark.run(order=0)
    def test_add_02(self):
        result = add(2, 2)
        assert 4 == result

    @pytest.mark.run(order=-2)
    def test_add_03(self):
        result = add(3, 2)
        assert 5 == result

结果

失败重试

安装

pip install pytest-rerunfailures

使用

在配置文件中的命令行参数中增加 --reruns n

结果

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值