pytest学习--pytest的skip和skipif

Skip 测试用例

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

2.调用来在测试执行或设置期间强制跳过pytest.skip(reason)功能。

3.使用pytest.skip(reason,allow_module_level = True)跳过整个模块级别。

import pytest


def is_true(a):
    if a > 0:
        return True
    else:
        return False


def test_01():
    a = 5
    b = -1
    assert is_true(a)
    assert not is_true(b)


@pytest.mark.skip(reason="预期错误")
def test_02():
    a = "admin"
    b = "hello world"
    assert a in b


def test_03():
    a = "admin"
    b = "admin"
    pytest.skip("不想执行了...")
    assert a == b


def test_04():
    a = 5
    b = 6
    pytest.skip("跳过这个模块,skipping tests", allow_module_level=True)
    assert a != b


if __name__ == '__main__':
    pytest.main(['-s', 'test_02.py'])

Skipif 测试用例

有条件地跳过某些内容,则可以使用skipif代替。

原文地址:https://www.cnblogs.com/wzhqzm/p/14392138.html