pytest 一些常用插件

  1. 用例失败后自动重新运行:pytest-rerunfailures,使用方法:
    1. 安装插件:pip install pytest-rerunfailures
    2. pytest test_x.py --reruns=n (失败后重运行的次数)
  2. 重复运行测试:pytest-repeat,使用方法:
    1. 安装插件:pip install pytest-repeat
    2. pytest test_x.py --count=n (重复运行的次数)
  3. 多线程执行测试任务:pytest-xdist,使用方法:
    1. 安装插件:pip install pytest-xdist
    2. pytest test_x.py -n [N, auto] (N:指定并发的进程数,auto:自动检测cpu数量)
  4. 为测试设置时间限制:pytest-timeout,使用方法:
    1. 安装插件:pip install pytest-timeout
    2. pytest test_x.py --timeout=n (时间限制,单位:秒)
  5. 用例失败时立刻显示错误的堆栈回溯信息:pytest-instafail,使用方法:
    1. 安装插件:pip install pytest-instafail
    2. pytest test_x.py --instafail
  6. 显示色彩和进度条(也能显示错误的堆栈信息):pytest-sugar,使用方法:
    1. 安装插件即可生效:pip install pytest-sugar

举例:pytest test_x.py --count=n     python 代码中:pytest.main(["test_xxx.py","--count=2"])

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值