标记预期失败

pytest.ini

[pytest]
addopts = -s -v
testpaths = ./scripts
python_files = test_case.py
python_classes = Test*
python_functions = test_*
xfail_strict = true

test_case.py

import pytest
def test_case_01():
assert 1

class TestCase(object):
"""加装饰器标记预期失败"""
@pytest.mark.xfail(conditon=1 < 2, reason="xxx")
def test_case_01(self):
"""预期失败 实际执行结果是失败"""
assert 0

@pytest.mark.xfail(condition=1 < 2, reason="ooo")
def test_case_02(self):
"""预期失败 实际执行结果是成功的"""
assert {"title":"v2ex"} != {"title": "V2EX"}

@pytest.mark.skipif(condition=1 > 2, reason="我就想跳过")
def test_case_03(self):
assert 0

if __name__ == '__main__':
pytest.main(["-s", "test_case.py"])

猜你喜欢

转载自www.cnblogs.com/zhang-da/p/12219400.html
今日推荐