当前位置: 首页 > news >正文

测试框架pytest教程(9)跳过测试skip和xfail

skip无条件跳过

使用装饰器

@pytest.mark.skip(reason="no way of currently testing this")
def test_example(faker):print("nihao")print(faker.words())

 方法内部调用

满足条件时跳过


def test_example():a=1if a>0:pytest.skip("unsupported configuration")

skipif满足条件跳过

import sys@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
def test_function():...

xfail预期失败

装饰器用法

@pytest.mark.xfail
def test_function():...

 内部调用

def test_function():if not valid_config():pytest.xfail("failing configuration (but should work)")

参数化时使用skip和xfail

import pytest@pytest.mark.parametrize(("n", "expected"),[(1, 2),pytest.param(1, 0, marks=pytest.mark.xfail),pytest.param(1, 3, marks=pytest.mark.xfail(reason="some bug")),(2, 3),(3, 4),(4, 5),pytest.param(10, 11, marks=pytest.mark.skipif(sys.version_info >= (3, 0), reason="py2k")),],
)
def test_increment(n, expected):assert n + 1 == expected

 

http://www.lryc.cn/news/140947.html

相关文章:

  • HTML <textarea> 标签
  • 探索图结构:从基础到算法应用
  • Redis之GEO类型解读
  • uniapp 微信小程序 路由跳转
  • 【android12-linux-5.1】【ST芯片】HAL移植后没调起来
  • Redis Lua脚本执行原理和语法示例
  • 百望云华为云共建零售数字化新生态 聚焦数智新消费升级
  • JMETER基本原理
  • elementUI自定义上传文件 前端后端超详细过程
  • 快速排序笔记
  • JAVA:(JSON反序列化Long变成了Integer)java.lang.Integer cannot be cast to java.lang.Long
  • ui设计师简历自我评价(合集)
  • Nginx 反向代理
  • [论文阅读笔记25]A Comprehensive Survey on Graph Neural Networks
  • iview时间控件 动态不可选日期 可选择24小时范围内 时间往后退24小时
  • Rest学习环境搭建:服务消费者
  • JVM内存模型介绍
  • 2000-2021年地级市产业升级、产业结构高级化面板数据
  • Java实现密码加密实现步骤【bcrypt算法】
  • 商城-学习整理-集群-K8S(二十三)
  • MATLAB算法实战应用案例精讲-【深度学习】强化学习
  • 时间和日期--Python
  • 【Git】学习总结
  • 手写Spring源码——实现一个简单的spring framework
  • 银河麒麟服务器、centos7服务器一键卸载mysql脚本
  • 【随笔】- 程序员的40岁后健身计划
  • 后端项目开发:集成Druid数据源
  • 深度学习11:Transformer
  • 免费开源跨平台视频下载器 支持数百站点视频和音频下载-ytDownloader
  • R包开发1:RStudio 与 GitHub建立连接