跳过执行测试用例

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跳过执行测试用例的更多相关文章

  1. Pytest测试框架(一):pytest安装及用例执行

    PyTest是基于Python的开源测试框架,语法简单易用,有大量的插件,功能非常多.自动检测测试用例,支持参数化,跳过特定用例,失败重试等功能. 安装 pip install -U pytest  ...

  2. pytest测试框架 -- 简介

    一.pytest测试框架简介: (1)pytest是python的第三方测试框架,是基于unittest的扩展框架,比unittest更简洁,更高效. (2)pytest框架可以兼容unittest用 ...

  3. Pytest测试框架(五):pytest + allure生成测试报告

    Allure 是一款轻量级.支持多语言的开源自动化测试报告生成框架,由Java语言开发,可以集成到 Jenkins. pytest 测试框架支持Allure 报告生成. pytest也可以生成juni ...

  4. 『德不孤』Pytest框架 — 1、Pytest测试框架介绍

    目录 1.什么是单元测试框架 2.单元测试框架主要做什么 3.单元测试框架和自动化测试框架有什么关系 4.Pytest测试框架说明 5.Pytest框架和Unittest框架区别 (1)Unittes ...

  5. pytest八:skip 跳过用例

    这是一个快速指南,介绍如何在不同情况下跳过模块中的测试1.无条件地跳过模块中的所有测试:pytestmark = pytest.mark.skip("all tests still WIP& ...

  6. Pytest测试框架(二):pytest 的setup/teardown方法

    PyTest支持xUnit style 结构, setup() 和 teardown() 方法用于初始化和清理测试环境,可以保证测试用例的独立性.pytest的setup/teardown方法包括:模 ...

  7. Pytest测试框架(三):pytest fixture 用法

    xUnit style 结构的 fixture用于初始化测试函数, pytest fixture是对传统的 xUnit 架构的setup/teardown功能的改进.pytest fixture为测试 ...

  8. 【pytest系列】- pytest测试框架介绍与运行

    如果想从头学起pytest,可以去看看这个系列的文章! https://www.cnblogs.com/miki-peng/category/1960108.html 前言​ ​ 目前有两种纯测试的测 ...

  9. Pytest测试框架入门到精通(一)

    Python测试框架之前一直用的是unittest+HTMLTestRunner,听到有人说Pytest很好用,所以这边给大家介绍一下Pytest的使用 pytest是一个非常成熟的全功能的Pytho ...

随机推荐

  1. Centos系统安装Python3.7

    服务器安装Python3.7,实测可用 原博客地址 首先要先安装依赖包: yum install zlib-devel bzip2-devel openssl-devel ncurses-devel ...

  2. Android 开发学习进程0.13 Androidstudio快捷键 xmlns

    xmlns XML namespace xml命名空间 其中主要是定义xml文件定义位置 前缀有三种,android app tools 后面为唯一标识符URI android 表示为引用自安卓系统 ...

  3. js对象的数据属性和访问器属性

    js面向对象 ECMA-262第5版在定义只有内部才用的特性(attribute)时,描述了属性(property)的各种特征.ECMA-262定义这些特性是为了实现javascript引擎用的,因此 ...

  4. node mssql 无法连接sql server

    mssql无法连接sql server主要有两种原因: Sql server使用的是Windows身份验证 Sql server并没有打开网络连接功能 1.打开Sql Server身份验证 参考这篇文 ...

  5. c# Attribute会不会影响性能

    Attribute很方便,标记一个类,设置这个类的额外信息,而不用另外设计存储这个信息. 那么频繁大量使用Attribute会不会影响类的性能. 为此,简单测试. 代码: 略............. ...

  6. 【CF1110E】 Magic Stones - 差分

    题面 Grigory has n n magic stones, conveniently numbered from \(1\) to \(n\). The charge of the \(i\)- ...

  7. 第四周:卷积神经网络 part 3

    第四周:卷积神经网络 part 3 视频学习 语义分割中的自注意力机制和低秩重建 语义分割(Semantic Segmentation) 概念:语义分割是在像素级别上的分类,属于同一类的像素都要被归为 ...

  8. 使用树莓派搭建LoRaWAN网关并接入腾讯云物联网开发平台

    安装树莓派环境 制作镜像 下载img文件烧录器 传送门:img文件烧录器地址,下载完成之后双击安装 下载镜像文件 传送门:树莓派系统镜像 推荐下载这个版本的img,因为有桌面,并且大小适中. 下载完之 ...

  9. 初识ABP vNext(4):vue用户登录&菜单权限

    Tips:本篇已加入系列文章阅读目录,可点击查看更多相关文章. 目录 前言 开始 登录 菜单权限 运行测试 最后 前言 上一篇已经创建好了前后端项目,本篇开始编码部分. 开始 几乎所有的系统都绕不开登 ...

  10. 群晖系统设置自动拍摄共享文件夹快照的教程【江东网 JDX86.COM】

    Snapshot Replication 是数据备份和还原的工具.企业需要数据保护以防止因意外删除.应用程序崩溃.数据损毁和病毒所造成的数据丢失. 1.在套件中心下载该套件 2.打开套件可以看到NAS ...