这些测试的过滤,或是对返回值的二重判断,

可以让测试过程更精准,测试结果更可控,

并可以更高层的应用测试脚本来保持批量化执行。

import pytest
import tasks
from tasks import Task

@pytest.fixture(autouse=True)
def initialized_tasks_db(tmpdir):
    tasks.start_tasks_db(str(tmpdir), 'tiny')

    yield

    tasks.stop_tasks_db()

@pytest.mark.skip(reason="misunderstood the API")
def test_unique_id_1():
    id_1 = tasks.unique_id()
    id_2 = tasks.unique_id()
    assert id_1 != id_2

def test_unique_id_2():
    ids = list()
    ids.append(tasks.add(Task('one')))
    ids.append(tasks.add(Task('two')))
    ids.append(tasks.add(Task('three')))
    uid = tasks.unique_id()
    assert uid not in ids

@pytest.mark.skipif(tasks.__version__ < '0.2.0',
                    reason="not supported until version 0.2.0")
def test_unique_id_3():
    id_1 = tasks.unique_id()
    id_2 = tasks.unique_id()
    assert id_1 != id_2

@pytest.mark.xfail(tasks.__version__ < '0.2.0',
                   reason="not supported until version 0.2.0")
def test_unique_id_4():
    id_1 = tasks.unique_id()
    id_2 = tasks.unique_id()
    assert id_1 != id_2

@pytest.mark.xfail()
def test_unique_id_is_a_duck():
    uid = tasks.unique_id()
    assert uid == "a duck"

@pytest.mark.xfail()
def test_unique_id_not_a_duck():
    uid = tasks.unique_id()
    assert uid != "a duck"

pytest mark中的skip,skipif, xfail的更多相关文章

  1. 10、pytest -- skip和xfail标记

    目录 1. 跳过测试用例的执行 1.1. @pytest.mark.skip装饰器 1.2. pytest.skip方法 1.3. @pytest.mark.skipif装饰器 1.4. pytest ...

  2. Pytest(9)skip跳过用例

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

  3. Pytest系列(9) - 参数化@pytest.mark.parametrize

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 pytest允许在多个级别启 ...

  4. Pytest学习笔记7-skip和skipif的使用

    前言 在实际的测试中,我们经常会遇到需要跳过某些测试用例的情况,pytest提供了skip和ifskip来跳过测试 下面我们就来通过一些例子看看skip和ifskip具体如何使用吧 skip的用法 使 ...

  5. pytest自动化6:pytest.mark.parametrize装饰器--测试用例参数化

    前言:pytest.mark.parametrize装饰器可以实现测试用例参数化. parametrizing 1.  下面是一个简单是实例,检查一定的输入和期望输出测试功能的典型例子 2.  标记单 ...

  6. httprunner学习20-跳过用例skip/skipIf/skipUnless

    前言 在实际工作中,我们有时候会需要对测试用例加判断,比如某个接口功能暂时去掉了,我们希望对这个用例skip不去执行. 当其它的接口依赖于登陆接口返回的token时候,如果登陆都失败了,后面的接口,我 ...

  7. pytest 用 @pytest.mark.usefixtures("fixtureName")或@pytest.fixture(scope="function", autouse=True)装饰,实现类似setup和TearDown的功能

    conftest.py import pytest @pytest.fixture(scope="class") def class_auto(): print("&qu ...

  8. pytest 用 @pytest.mark.usefixtures("fixtureName")装饰类,可以让执行每个case前,都执行一遍指定的fixture

    conftest.py import pytest import uuid @pytest.fixture() def declass(): print("declass:"+st ...

  9. 5.@pytest.mark.parametrize()数据驱动

    简介: pytest.mark.parametrize 是 pytest 的内置装饰器,它允许你在 function 或者 class 上定义多组参数和 fixture 来实现数据驱动. @pytes ...

随机推荐

  1. python eval 用法

    eval 功能:将字符串str当成有效的表达式来求值并返回计算结果. 语法: eval(source[, globals[, locals]]) -> value 参数: source:一个Py ...

  2. day19 IO编程

    文件:文件是数据源(保存数据的地方)的一种. 文件在程序中是以流的形式来操作的 内存(程序)到文件是输出流,文件到内存(程序)是输入流. 字节流:可用于读写的二进制文件及任何类型文件. 字符流:可以用 ...

  3. Java poi读取,写入Excel2003

    Java poi读取,写入Excel2003 相关阅读:poi读写Excel2007:http://www.cnblogs.com/gavinYang/p/3576741.htmljxl读写excel ...

  4. 权限 mock location

    1.集成环信的时候,该权限报错: mock location权限是是“允许程序创建模拟位置”,主要是提供用于测试.打包的时候并不需要,所以解决办法分两步: 1.声明tools 2.添加忽略:

  5. [SDOI2010]外星千足虫 题解 高斯消元+bitset简介

    高斯消元 + bitset 简介: 高斯消元其实就是以加减消元为核心求唯一解.这道题还是比较裸的,可以快速判断出来.我们将每一只虫子看作一个未知数,这样根据它给出的 m 组方程我们可以高斯消元得出每一 ...

  6. 【数据库】SQL经典面试题 - 行列转换二 - 列转行

    本帖子是行转列的一个逆向操作——列转行,看下面一个面试题 面试题2: 柠檬班第30期学生要毕业了,他们的Linux.MySQL.Java成绩数据表 tb_lemon_grade_column中, 表中 ...

  7. host映射方法

    host映射: host是根据TCP/IP for Windows 的标准来工作的,它的作用是包含IP地址和Host name(主机名)的映射关系,是一个映射IP地址和Host name(主机名)的规 ...

  8. 树形dp&&树的重心(D - Godfather POJ - 3107)

    题目链接:https://cn.vjudge.net/contest/277955#problem/D 题目大意:求树的重心(树的重心指的是树上的某一个点,删掉之后形成的多棵树中节点数最大值最小). ...

  9. PyText

    Facebook开源了自家工程师们一直在用的NLP建模框架PyText.这个框架,每天要为Facebook旗下各种应用处理超过10亿次NLP任务,Facebook AI的工业级NLP开源框架.(简化部 ...

  10. Dream------Hadoop--FSDataInputStream和FSDataOutputStream

    一.FSDataInputStream    FileSystem中的open()方法实际上返回的是一个FSDataInputStream,而不是标准的java.io类.这个类是java.io.Dat ...