pytest中xfail、xpass、skip的简单使用
概述:
pytest.skip():跳过当前case,这句之前的代码正常执行,之后的不执行
pytest.xfail():标记当前case为xfail,这句之前的代码正常执行,之后的不执行
@pytest.mark.xfail:如果被注解的case执行通过,则状态为xpass。如果不通过状态为xfail
import pytest class TestDemo(object): @pytest.fixture() def error_fixture(self): assert 0 def test_ok(self): print('ok') def test_fail(self): assert 0 def test_error(self, error_fixture): pass def test_skip(self): print('before') pytest.skip('skip case') print('after') def test_xfail(self): print('before') pytest.xfail('xfail case') print('after') @pytest.mark.xfail def test_xpass(self): assert 1 if __name__=='__main__': pytest.main(['-s', 'test_demo.py'])