pytest.mark.skip可以标记无法在某些平台上运行的测试功能,或者你希望失败的测试功能

skip意味着只有在满足某些条件时才希望测试通过,否则pytest应该跳过运行测试。常见事例时非windows平台上跳过仅限windows的测试,或者跳过测试依赖于当前不可用的外部资源(例如数据库)

xfail意味着你希望测试由于某种原因而失败。一个常见的例子时对功能的测试尚未实施,或尚未修复的错误。当测试通过时尽管预计会失败(标有pytest.mark.xfail),它是一个xpass,将在测试摘要中报告。

pytest计数并分别列出skip和xfail测试,未显示有关跳过 xfailed测试的详细信息默认情况下,以避免混乱输出。可以使用 -r选项查看与“short”字母对应的详细信息显示在测试进度中

pytest -rxXs     显示额外的信息在xfailed,xpassed和skipped 测试中。有关-r的信息,运行pytest -h查看

skip

跳过测试函数的最简单方法是使用跳过装饰器标记它,可以传递一个可选的原因:

#!/usr/bin/env/python
# -*-coding:utf-8-*- import pytest @pytest.mark.skip(reason="input your skip reason")
def test_the_skip():
...

或者,也可以通过调用赖在测试执行或设置期间强制跳过pytest.skip(reason)功能:

def valid_config():
return True def test_function():
if not valid_config():
pytest.skip("reason")

也可以使用pytest.skip(reason,allow_module_level=True)跳过整个模块级别:

import pytest

if not pytest.config.getoption():
pytest.skip("reason",allow_module_level= True)

skipif

如果你希望有条件的跳过某些内容,则可以使用skipif代替,这是标记测试的示例在python3.6之前的揭示其上运行时要跳过的函数

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

你也可以在模块之间共享skipif标记。参考以下的案例,第二个是:导入标记并在另一个测试模块中重复使用它:

# test_skip.py
minversion = pytest.mark.skipif(sys.version_info< (3,6), reason="requires python3.6 or higher") @minversion
def test_function():
print("hello")
...
# test.py
#!/usr/bin/env/python
# -*-coding:utf-8-*- from test_skip import minversion @minversion
def test_fun():
'''hehehe'''
print(test_fun.__doc__)

skip类或模块

可以在类上使用skipif标记(与任何其他标记一样):

#!/usr/bin/env/python
# -*-coding:utf-8-*-
import pytest,sys @pytest.mark.skipif(sys.platform == 'win32',reason="does not run on windows")
class TestPosixCalls(object):
def test_function(self):
"will not be setup or run under 'win32' platform"
print("hello")

如果条件为True,则此标记将为该类的每个测试方法生成跳过结果

警告:强烈建议不要在使用继承的类上使用skipif。 pytest中的一个已知错误标记可能会导致超类中的意外行为。

如果要跳过模块的所有测试功能,可以在全局级别使用pytestmark名称

pytestmark = pytest.mark.skipif(...)

如果将多个skipif装饰器应用于测试函数,则如果任何跳过条件为真,则将跳过它

skip缺少导入依赖项

您可以在模块级别或测试或测试设置功能中使用以下帮助程序

docutils = pytest.importorskip("docutils")

如果无法在此处导入docutils,则会导致测试跳过结果。 你也可以跳过库的版本号

docutils = pytest.importorskip("docutils", minversion="0.3")

将从指定模块的version属性中读取版本。

这是一个快速指南,介绍如何在不同情况下跳过模块中的测试

1.无条件地跳过模块中的所有测试:

pytestmark = pytest.mark.skip(“all tests still WIP”)

2.根据某些条件跳过模块中的所有测试

pytestmark = pytest.mark.skipif(sys.platform == “win32”, “tests for linux
˓→ only”

3.如果缺少某些导入,则跳过模块中的所有测试

pexpect = pytest.importorskip(“pexpect”)

pytest 10 skip跳过测试用例的更多相关文章

  1. pytest测试框架 -- skip跳过执行测试用例

      跳过执行测试用例 1.@pytest.mark.skip(reason=" ") -- 跳过执行测试函数 可传入一个非必须参数reason表示原因 import pytest@ ...

  2. Pytest(9)skip跳过用例

    前言 pytest.mark.skip可以标记无法在某些平台上运行的测试功能,或者您希望失败的测试功能 Skip和xfail: 处理那些不会成功的测试用例 你可以对那些在某些特定平台上不能运行的测试用 ...

  3. 【pytest官方文档】解读Skipping test functions,跳过测试用例详解

    有时候,为了满足某些场景的需要,我们知道有些测试函数在这时候肯定不能执行,或者执行了也会失败.那么我们 可以选择去跳过这个测试函数,这样也就不会影响整体的测试函数运行效果,不至于在你运行的众多绿色通过 ...

  4. 『德不孤』Pytest框架 — 4、Pytest跳过测试用例

    目录 1.无条件跳过skip 2.有条件跳过skipif 3.练习 自动化测试执行过程中,我们常常出现这种情况:因为功能阻塞,未实现或者环境有问题等等原因,一些用例执行不了, 如果我们注释掉或删除掉这 ...

  5. pytest八:skip 跳过用例

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

  6. MOOC(7)- case依赖、读取json配置文件进行多个接口请求-跳过测试用例(6)

    初始化.跳过测试用例 # test_class_6.py import unittest from mock import mock from day_20200208_mooc.base.inter ...

  7. MongoDB limit 选取 skip跳过 sort排序 方法

    MongoDB  limit 选取 skip跳过 sort排序 在mysql里有order by  MongoDB用sort代替order by > db.user.find() { " ...

  8. MongoDB之Limit选取Skip跳过Sort排序

    1.Limit选取 我要从Document中取出多少个 只要2条Document db.Wjs.find().limit(2) 2.Skip跳过 我要跳过多少个Document 我要跳过前两个Docu ...

  9. MongoDB 之 Limit 选取 Skip 跳过 Sort 排序 MongoDB - 7

    我们已经学过MongoDB的 find() 查询功能了,在关系型数据库中的选取(limit),排序(sort) MongoDB中同样有,而且使用起来更是简单 首先我们看下添加几条Document进来 ...

随机推荐

  1. 一些常用的meta标签

    <!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 --> <html lang="zh-cmn-Hans"&g ...

  2. iead2018创建JavaWe工程

    菜单栏中 File-> Project,弹出如下界面,选择 Java并勾选 Web Application 填写 Project Name 配置 tomcat 点击右上角的绿色的小锤子,然后打开 ...

  3. Nginx+uWSGI启动Django

    在之前的几篇博客中对Django的功能做了初步实践,这里链接贴一下: Django的安装和启动 Django之--网页展示Hello World! Django之--通过MVC架构的html模板展示H ...

  4. C# 反射的例子

    通过字符串变量访问控件 string t = "textbox1"; TextBox tb = (TextBox)this.GetType().GetField(t, System ...

  5. Navicat如何导出Excel格式表结构

    SELECTCOLUMN_COMMENT 字段名,COLUMN_NAME code,COLUMN_TYPE 数据类型,DATA_TYPE 字段类型,CHARACTER_MAXIMUM_LENGTH 长 ...

  6. Java基础——0 前言

  7. Node、TS、Koa学习笔记

    这样定义可以轻松拿到gender属性 这样定义,函数内显示没有gender 这种方法能得到gender但是函数内部没有gender 这种方式能到gender 但是在函数里施symbel属性,外部不能访 ...

  8. day12-内置模块学习(三)

    我的博客呀,从以前的预习变成了复习了,复习的东西还没有写完,哎 今日目录 1.序列化模块 2.加密模块 3.包的使用 4.random模块 5.shutil模块 开始今日份总结 1.序列化模块 在学习 ...

  9. Java 通过地址获取经纬度 - 高德地图

    一.添加依赖 <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-v ...

  10. 步步深入:MySQL架构总览->查询执行流程->SQL解析顺序(转)

    文章转自   http://www.cnblogs.com/annsshadow/p/5037667.html https://www.cnblogs.com/cuisi/p/7685893.html