目录
跳过测试用例
常用的标记有以下几种:
- skip:只有当某些条件满足时,才执行测试用例,否则跳过整个测试用例的执行
- xfail:因为一个确切的原因,我们知道这个用例会失败。例如阻塞于某个已知的BUG
pytest默认不显示skip和xfail用例的详细信息,我们可以通过-r选项来自定义这种行为
具体的规则如下:
- f:failed
- E:Error
- s: Skipped
- x: xfailed
- X: Xpassed
- p: passed
- P: Passed with output
- a: all except passed(p/P)
- A: All
@pytest.mark.skip 装饰器
语法@pytest.mark.skipif(条件, reason="原因")
"""演示 pytest 跳过方法的使用"""
import pytest
version = 25
class TestDemo:
def test_demo1(self):
print("this is demo1")
@pytest.mark.skip(reason="无条件跳过")
def test_demo2(self):
print("this is a demo2")
@pytest.mark.skipif(version >= 25, reason="xxxxxxxxx")
def test_demo2(self):
print("this is a demo2")
if __name__ == '__main__':
pytest.main(['-s', "06_pyest_skip.py"])
执行后结果如下:
============================= test session starts =============================
collecting ... collected 3 items
06_pyest_skip.py::TestDemo::test_demo1 PASSED [ 33%]this is demo1
06_pyest_skip.py::TestDemo::test_demo2 SKIPPED (无条件跳过) [ 66%]
Skipped: 无条件跳过
06_pyest_skip.py::TestDemo::test_demo3 SKIPPED (xxxxxxxxx) [100%]
Skipped: xxxxxxxxx
======================== 1 passed, 2 skipped in 0.01s =========================
标签:管理,skip,pytest,mark,Pytest,test,测试用例,跳过
From: https://www.cnblogs.com/czzz/p/17061184.html