pytest测试框架 -- skip跳过执行测试用例
跳过执行测试用例
1、@pytest.mark.skip(reason=" ") -- 跳过执行测试函数
可传入一个非必须参数reason表示原因
import pytest
@pytest.mark.skip(reason="no reason")
def test_01():
print("---用例a执行---") class TestCase(): @pytest.mark.skip(reason="no reason")
def test_02(self):
print("---用例b执行---") def test_03(self):
print("---用例c执行---") 输出结果:
test_fixture2.py ss---用例c执行---
2、@pytest.mark.skipif(condition...) -- 若满足condition,则跳过测试函数
传入condition参数为判断条件,可以选择传入非必须参数reason;如果多个标签一起使用,满足其中一个跳过条件则会跳过该测试函数。
import pytest
def test_01():
print("---用例a执行---") class TestCase(): #当多个@pytest.mark.skipif()标签时,若满足一个,则跳过测试函数
@pytest.mark.skipif(condition='a' >= 'b', reason="no reason")
@pytest.mark.skipif(condition='a' <= 'b', reason="no reason")
def test_02(self):
print("---用例b执行---") def test_03(self):
print("---用例c执行---") 输出结果:
test_fixture2.py ---用例a执行---
.s---用例c执行---
3、自定义@pytest.mark.skip()标签
myskip = pytest.mark.skip() 或 myskip = pytest.mark.skipif(condition=...)
装饰时用该变量代替标签即可:@myskip
import pytest
# myskip = pytest.mark.skip()
myskip = pytest.mark.skipif(condition=2>1, reason="no reason") @myskip
def test_01():
print("---用例a执行---") class TestCase(): @myskip
def test_02(self):
print("---用例b执行---") def test_03(self):
print("---用例c执行---") 输出结果:
test_fixture2.py ss---用例c执行---
4、通过pytest.skip()方法跳过测试函数
import pytest def test_01():
pytest.skip(msg="no reason")
print("---用例a执行---") class TestCase(): def test_02(self):
pytest.skip()
print("---用例b执行---") def test_03(self):
print("---用例c执行---") 输出结果:
test_fixture2.py ss---用例c执行--
5、跳过测试类
跳过测试类其实和跳过测试方法一样,使用@pytest.mark.skip()和@pytest.mark.skipif()两个标签,用他们装饰测试类就好啦。
import pytest myskip = pytest.mark.skip(reason="no reason") def test_01():
print("---用例a执行---") @myskip
class TestCase(): def test_02(self):
print("---用例b执行---") def test_03(self):
print("---用例c执行---") 输出结果:
test_fixture2.py ---用例a执行---
6、跳过模块
使用pytestmark(不可更改变量名)变量,让他等于标签即可。
import pytest pytestmark = pytest.mark.skip(condition=2>1, reason='no reason') def test_01():
print("---用例a执行---") class TestCase(): def test_02(self):
print("---用例b执行---") def test_03(self):
print("---用例c执行---") 输出结果:
test_fixture2.py sss
7、pycharm中运行多个测试文件
依次将要运行的文件名写在后面即可,用逗号隔开,无需链表元组等形式。
if __name__ == "__main__":
pytest.main(['-s', 'test_fixture1.py', 'test_fixture2.py'])
参考:https://blog.csdn.net/qq_39721240/article/details/88726606
pytest测试框架 -- skip跳过执行测试用例的更多相关文章
- Pytest测试框架(一):pytest安装及用例执行
PyTest是基于Python的开源测试框架,语法简单易用,有大量的插件,功能非常多.自动检测测试用例,支持参数化,跳过特定用例,失败重试等功能. 安装 pip install -U pytest ...
- pytest测试框架 -- 简介
一.pytest测试框架简介: (1)pytest是python的第三方测试框架,是基于unittest的扩展框架,比unittest更简洁,更高效. (2)pytest框架可以兼容unittest用 ...
- Pytest测试框架(五):pytest + allure生成测试报告
Allure 是一款轻量级.支持多语言的开源自动化测试报告生成框架,由Java语言开发,可以集成到 Jenkins. pytest 测试框架支持Allure 报告生成. pytest也可以生成juni ...
- 『德不孤』Pytest框架 — 1、Pytest测试框架介绍
目录 1.什么是单元测试框架 2.单元测试框架主要做什么 3.单元测试框架和自动化测试框架有什么关系 4.Pytest测试框架说明 5.Pytest框架和Unittest框架区别 (1)Unittes ...
- pytest八:skip 跳过用例
这是一个快速指南,介绍如何在不同情况下跳过模块中的测试1.无条件地跳过模块中的所有测试:pytestmark = pytest.mark.skip("all tests still WIP& ...
- Pytest测试框架(二):pytest 的setup/teardown方法
PyTest支持xUnit style 结构, setup() 和 teardown() 方法用于初始化和清理测试环境,可以保证测试用例的独立性.pytest的setup/teardown方法包括:模 ...
- Pytest测试框架(三):pytest fixture 用法
xUnit style 结构的 fixture用于初始化测试函数, pytest fixture是对传统的 xUnit 架构的setup/teardown功能的改进.pytest fixture为测试 ...
- 【pytest系列】- pytest测试框架介绍与运行
如果想从头学起pytest,可以去看看这个系列的文章! https://www.cnblogs.com/miki-peng/category/1960108.html 前言 目前有两种纯测试的测 ...
- Pytest测试框架入门到精通(一)
Python测试框架之前一直用的是unittest+HTMLTestRunner,听到有人说Pytest很好用,所以这边给大家介绍一下Pytest的使用 pytest是一个非常成熟的全功能的Pytho ...
随机推荐
- JavaScript 中 Blob对象的初步认识
Blob Binary Large Object的缩写,二进制大对象 虽然在前端中开发并不常见,但是实际上MySql数据库中,可以通过设置一个Blob类型的数据来存储一个Blob对象的内容 语法 le ...
- 日记——递归or搜索?
好久没发博了,今天发一篇. 这两天学校功课比较紧,编程稍微放了放做题量. 抽空学了学深搜,感谢zah同学给我讲解dfs,浅显易懂,我很快就适应了. 做了几个基础题,没有想象中那么难(菜鸡BB,因为题简 ...
- MySQL空间函数实现位置打卡
项目需求是跟用户当前位置判断是否在给定的地理位置范围内,符合位置限制才可以打卡,其中的位置范围是一个或多个不规则的多边形.如下图,判断用户是在清华还是北大. 图形获取区域坐标 因为项目前端使用微信小程 ...
- Ubuntu LNMP环境的搭建
一.安装nginx Step1:安装: sudo apt-get install nginx Step2:查看ngnix 运行状态 : service nginx status 查看80端口是否开启: ...
- JavaScript学习系列博客_16_JavaScript中的函数(Function)简介
函数(Function) - 函数也是一个对象,也具有普通对象的功能 - 函数中可以封装一些代码,在需要的时候可以去调用函数来执行这些代码:当调用函数时,函数中封装的代码会按照顺序执行. - 使用ty ...
- 9.oracle表查询关键字
1.使用逻辑操作符号问题:查询工资高于500或者是岗位为manager的雇员,同时还要满足他们的姓名首字母为大写的J? select * from emp where (sal > 500 or ...
- golang 判断IPv4 or IPv6 address
import strings func IsIPv4(address string) bool { return strings.Count(address, ":") < ...
- 牛客网PAT练兵场-德才论
题解:用sort排序即可 题目地址:https://www.nowcoder.com/questionTerminal/97b6a49a85944650b2e3d0660b91c324 /** * C ...
- jmeter参数化之 【CSV Data Set Config/CSV数据配置文件】
这里以登录功能为例: 1.新建.txt文件,将参数值写入到txt文件中(多个参数值如:用户名,密码 之间以逗号隔开),将文件放置在想要放置的目录下 2.添加csv数据文件设置 右键线程组->添加 ...
- seo工程师是什么,需要什么技能?
http://www.wocaoseo.com/thread-222-1-1.html seo工程师是什么,SEO工程师是目前需求较大的一种职业,是搜索引擎营销的一种,主要是是通过网站优化技 ...