首页 > 其他分享 >pytest + yaml 框架 -37.mark 标记对用例运行时长断言

pytest + yaml 框架 -37.mark 标记对用例运行时长断言

时间:2023-06-18 10:37:52浏览次数:45  
标签:用例 37 mark yaml pytest sleep test runtime

前言

pytest 执行用例的时候,我们希望对用例的运行时间断言,当用例执行时长大于预期标记此用例失败。
@pytest.mark.runtime(1) 运行时长单位是秒
此插件已打包上传到pypi https://pypi.org/project/pytest-runtime-yoyo/1.0.0/

环境准备

pip install pytest-yaml-yoyo

此功能在v1.3.1 版本上实现

代码中实现

基本示例 test_demo.py

import pytest
import time


def test_a1():
    time.sleep(2)


@pytest.mark.runtime(1)
def test_a2():
    time.sleep(2)

运行结果

======================== short test summary info =====================
    FAILED test_demo.py::test_a2
    ======================== 1 failed, 1 passed in 4.18s ===============

在 yaml 用例中实现

在yaml 中添加 runtime

config:
  name: yy


test_a1:
  name: a11
  mark: runtime(1)
  sleep: 2
  print: "xx111"

test_a2:
  name: a22
  sleep: 2
  print: "xx22"

也可以在config 中添加runtime 对整个yaml 中的用例标记

config:
  name: yy
  mark: runtime(1)


test_a1:
  name: a11
  sleep: 2
  print: "xx111"

test_a2:
  name: a22
  sleep: 2
  print: "xx22"

如果config 中和用例中都有runtime ,那么用例的runtime优先级>config 中的runtime

全局用例配置

对全部用例设置 runtime 标记,可以在 pytest.ini 中设置全局配置

[pytest]

runtime = 3

也可以在执行 pytest 命令的时候带上命令行参数--runtime

pytest --runtime=3

优先级是: 命令行参数 > pytest.ini 配置
全局配置只针对yaml 中config,测试用例没标记 runtime 的用例生效。
如果yaml 中config,测试用例有标记 runtime,那么优先级是大于全局配置的。



标签:用例,37,mark,yaml,pytest,sleep,test,runtime
From: https://blog.51cto.com/u_15249893/6507335

相关文章

  • pytest + yaml 框架 -38.企业微信机器人通知
    前言v1.3.2版本支持企业微信机器人发送报告通知了。pipinstallpytest-yaml-yoyo获取企业微信机器人token企业机器人相关接口可以看官方文档https://developer.work.weixin.qq.com/document/path/91770创建群聊机器人获取到webhook访问地址https://qyapi.weixin.qq.com/cgi-bin/......
  • 将HTML网页转换为Markdown格式的工具及方法
    保存博客文章早期在markdown语法还没有推出来之前,编写blog是在网页上或olw写的,也就是文章是保存在对方的主机上。最近计划把我在博客园的一些早期html文章转换成markdown的文件,因为md更好地保存,经过实践之后,我保留这两个工具。PS.也尝试过python的脚本版本,但运行时会有报错,就......
  • 如何翻译 Markdown 文件?-2-几种商业及开源解决方案介绍
    背景近期在搭建英文博客-<e-whisper.com>,需要对现有的所有中文Markdown翻译为英文。需求如下:将Markdown文件从中文(zh-CN)翻译为英文(en)翻译后要保留Markdown的完整格式部分Markdownblock不需要翻译,如:front-matter、代码块等但是实际使用中,试了好几款翻译(......
  • 如何翻译 Markdown 文件?-2-几种商业及开源解决方案介绍
    背景近期在搭建英文博客-<e-whisper.com>,需要对现有的所有中文Markdown翻译为英文。需求如下:将Markdown文件从中文(zh-CN)翻译为英文(en)翻译后要保留Markdown的完整格式部分Markdownblock不需要翻译,如:front-matter、代码块等但是实际使用中,试了好几款翻译......
  • Yet Another Minimization Problem(CF1637D)
    \(\text{Des}\)Youaregiventwoarrays$a$and$b$,bothoflength$n$.Youcanperformthefollowingoperationanynumberoftimes(possiblyzero):selectanindex$i$($1\leqi\leqn$)andswap$a_i$and$b_i$.Let'sdefi......
  • Mark Fan:A computational model study on the mechanical response mechanism of asp
    WuhanJiangxiaRoadandBridgeEngineeringCo.,LtdSchoolofCivilEngineeringandArchitecture,WuhanInstituteofTechnologyMarkFan 15927602711Introduction:Asphaltisacommonlyusedmaterialinroadconstruction,anditsmechanicalpropertiespl......
  • Luogu3792 由乃与大母神原型和偶像崇拜 - 线段树 - set -
    题目链接:https://www.luogu.com.cn/problem/P3792题解:一点小小的空间震撼(ML:125MB)首先询问可以转化成:区间\([l,r]\)的\(max-min+1=r-l+1\)并且区间内没有重复元素。可以考虑对每个点\(i\)记一个前驱结点\(pr_i\),表示\(a_{pr_i}=a_i\),且\(pr_i\)是\(i\)前面离\(i\)......
  • 主叫是053158263720,被叫是手机号,转向gateway 是gw4 ,并且被叫前缀加上88
    可以使用以下拨号计划来实现: <include><contextname="public"><extensionname="forward_call"><conditionfield="caller_id_number"expression="^053158263720$"/><conditionfield="destination_number&......
  • pytest + yaml 框架 -38.企业微信机器人通知
    前言v1.3.2版本支持企业微信机器人发送报告通知了。pipinstallpytest-yaml-yoyo获取企业微信机器人token创建群聊机器人获取到webhook访问地址https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=*********************key=后面的这串就是我们要的token配置......
  • vue3:vue+nginx+php进行服务端部署的配置(nginx/1.18.0 / [email protected])
    一,开发环境中的配置:1,前端:vue的vue.config.jsconst{defineConfig}=require('@vue/cli-service')module.exports=defineConfig({transpileDependencies:true,publicPath:process.env.NODE_ENV==="production"?"./":"/&qu......