为了避免由于环境发生改变或者其他原因造成的测试脚本的阻塞,可用skip跳过某些用例。
1.@pytest.mark.skip()的功能是跳过,可装饰于类与方法。括号内(reason=‘跳过原因’)
2.@pytest.mark.skipif()的功能是跳过,可装饰于类与方法。括号内(判断, reason=‘跳过原因’)
3.pytest.skip()也是跳过,不同于1的是它一般用于方法内,当进行if条件判断后执行该语句。1则更类似于一个烙印,打上后直接跳过。
import pytest
class Test1(object):
def test_1(self):
print('1')
class Test2(object):
@pytest.mark.skip(reason='跳过Test2的test_2')
def test_2(self):
print('2')
def test_3(self):
print('3')
@pytest.mark.skip(reason='跳过Test3')
class Test3(object):
def