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 ...
随机推荐
- vue scss 样式穿透
使用2个style的方式不够优雅,可以使用下面方式做样式穿透 .normal-field /deep/ .el-form-item { margin-bottom: 0px; } .normal-fi ...
- JavaScript 中 Blob对象的初步认识
Blob Binary Large Object的缩写,二进制大对象 虽然在前端中开发并不常见,但是实际上MySql数据库中,可以通过设置一个Blob类型的数据来存储一个Blob对象的内容 语法 le ...
- 01 树莓派4B—C语言编程——GPIO
#include <stdio.h>#include <wiringPi.h> int main( void){ int LED1 = 1; int LED4 = 4; wir ...
- 记一次mysql数据库被勒索(中)
背景在上一篇文章里面已经提过了. 现在面临的问题是nextcloud没有mysql数据库,用不起来了. 因为文件没丢,一种方法是启动新的mysql数据库,把文件重新提交一次. 为了程序员的面子,没有选 ...
- MapReduce之MapJoin案例
@ 目录 使用场景 优点 具体办法:采用DistributedCache 案例 需求分析 代码实现 使用场景 Map Join 适用于一张表十分小.一张表很大的场景. 优点 思考:在Reduce 端处 ...
- Html5与CSS3(选择器)
<!-- 作者:offline 时间:2018-03-21 描述:1.全选择器 *{属性1:属性值2:属性2:属性值2:...:} 2.元素(标签)选择器 标签名{属性1:属性值2:属性2:属性 ...
- python re之search/match差别
search → find something anywhere in the string and return a match object. match → find something at ...
- 正规式转化为DFA
https://www.bilibili.com/video/BV1dj411f7AR?p=50 例题:
- Oracle和Mysql分页的区别
一.Mysql使用limit分页 select * from stu limit m, n; //m = (startPage-1)*pageSize,n = pageSize PS: (1)第一个参 ...
- linux驱动之内核多线程(四)
本文摘自 http://www.cnblogs.com/zhuyp1015/archive/2012/06/13/2548494.html 自己创建的内核线程,当把模块加载到内核之后,可以通过:ps ...