Pytest13--跳过测试函数
原创
©著作权归作者所有:来自51CTO博客作者分享智道的原创作品,请联系作者获取转载授权,否则将追究法律责任
跳过测试函数
根据特定的条件,不执行标识的测试函数.
方法:
skipif(condition, reason=None)
参数:
condition:跳过的条件,必传参数
reason:标注原因,必传参数
使用方法:
@pytest.mark.skipif(condition, reason="xxx")
编写test_demo01.py
import pytest
class Test_ABC:
def setup_class(self):
print("------->setup_class")
def teardown_class(self):
print("------->teardown_class")
def test_a(self):
print("------->test_a")
assert 1
@pytest.mark.skipif(condition=2 > 1, reason="跳过该函数") # 跳过测试函数test_b
def test_b(self):
print("------->test_b")
assert 0
"""执行结果:
test_abc.py
------->setup_class
------->test_a # 只执行了函数test_a
.
------->teardown_class
s # 跳过函数```"""
作者:暄总-tester