#设置xfail_strict = true可以让那些标记为@pytest.mark.xfail但实际通过的测试用例被报告为失败
import pytest
def test_hello():
print("hello World!")
#预期会失败 结果运行失败 会被标记为xfail
@pytest.mark.xfail
def test1():
a="hello"
b="helloworld"
assert a==b
#预期会失败 结果运行通过 会被标记为xpass
@pytest.mark.xfail
def test2():
a="hello"
b="helloworld"
assert a != b
if __name__ == '__main__':
pytest.main(["-v","testXPass.py"])
#运行结果 1 passed, 1xfailed,1 xpassed in 0.27seconds
'''
预期会失败 结果运行失败 会被标记为xfail,预期会失败 结果运行通过 会被标记为xpass,
为了让两个都显示x'fail 那就加个配置 xfail_strict=true
'''
# pytest.ini
# [pytest]
# markers=
# webtest:Run the webtest case
# hello:Run the hello case
# xfail_strict=true
#运行结果:1 failed, 1 passed, 1 xfailed in 0.16 seconds