PyTest之预期失败
当某个bug,修复优先级比较低,暂时不用修复。此时,改自动化用例运行时,肯定会报错,那么我们就可以用 @pytest.mark.xfail
来标记,用例执行的结果会被标记为xfailed
,而不是failed
。
#test_xfail.py
import pytest
class TestMyCode:
@pytest.mark.xfail(reason="bug待修复【OPRAUPL-7166】")
def test_xfail_001(self):
assert 1 == 2
结果:
============================= 1 xfailed in 0.15s ==============================
当bug被修复后,用例自动执行通过,但是因为我们打了@pytest.mark.xfail
标记,所以执行的结果被统计为xpassed
import pytest
class TestMyCode:
@pytest.mark.xfail(reason="bug待修复【OPRAUPL-7166】")
def test_xfail_002(self):
assert 1 == 1
结果:
============================= 1 xpassed in 0.02s ==============================
这样将显式地提醒我们:业务逻辑有变化,或者有bug被修复,测试用例可能需要调整,需要引起注意