其他分享
首页 > 其他分享> > 标记预期失败

标记预期失败

作者:互联网

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"])

标签:case,__,标记,assert,预期,pytest,失败,test,xfail
来源: https://www.cnblogs.com/zhang-da/p/12219400.html