首页 > 其他 > 详细

pytest xfail的使用

时间:2020-04-08 16:47:52      阅读:87      评论:0      收藏:0      [点我收藏+]

@pytest.mark.xfail:

期望测试用例是失败的,但是不会影响测试用例的的执行;

如果测试用例执行失败的则结果是xfail(不会额外显示出错误信息);

如果测试用例执行成功的则结果是xpass;

import pytest
class TestClass():
    @pytest.mark.xfail
    def test_one(self):
        print("test_one方法执行")
        assert  1==2

    def test_two(self):
        print("test_two方法执行")
        assert  o in love

    def test_three(self):
        print("test_three方法执行")
        assert 3-2==1

执行结果:

C:\Users\cale\checkapi\test>pytest test_gy.py -v
=========================================================================================================== test session starts ============================================================================================================
platform win32 -- Python 3.7.3, pytest-5.2.1, py-1.8.0, pluggy-0.13.0 -- c:\users\ipharmacare\python37\python.exe
cachedir: .pytest_cache
metadata: {‘Python‘: ‘3.7.3‘, ‘Platform‘: ‘Windows-10-10.0.17134-SP0‘, ‘Packages‘: {‘pytest‘: ‘5.2.1‘, ‘py‘: ‘1.8.0‘, ‘pluggy‘: ‘0.13.0‘}, ‘Plugins‘: {‘html‘: ‘2.0.0‘, ‘metadata‘: ‘1.8.0‘, ‘rerunfailures‘: ‘7.0‘}}
rootdir: C:\Users\cale\checkapi\test
plugins: html-2.0.0, metadata-1.8.0, rerunfailures-7.0
collected 3 items

test_gy.py::TestClass::test_one XFAIL [ 33%]
test_gy.py::TestClass::test_two PASSED [ 66%]
test_gy.py::TestClass::test_three PASSED [100%]

======================================================================================================= 2 passed, 1 xfailed in 0.31s =======================================================================================================

 pytest.fail(reason=‘ ‘):

在测试用例中调用,该方法之后的代码不再运行,结果中标记为xfail

import pytest
class TestClass():

    def test_one(self):
        print("test_one方法执行")
        pytest.xfail(reason=该功能尚未完善)
        assert  1==1

    def test_two(self):
        print("test_two方法执行")
        assert  o in love

    def test_three(self):
        print("test_three方法执行")
        assert 3-2==1

运行结果:

C:\Users\cale\checkapi\test>pytest test_gy.py -v
=========================================================================================================== test session starts ============================================================================================================
platform win32 -- Python 3.7.3, pytest-5.2.1, py-1.8.0, pluggy-0.13.0 -- c:\users\ipharmacare\python37\python.exe
cachedir: .pytest_cache
metadata: {‘Python‘: ‘3.7.3‘, ‘Platform‘: ‘Windows-10-10.0.17134-SP0‘, ‘Packages‘: {‘pytest‘: ‘5.2.1‘, ‘py‘: ‘1.8.0‘, ‘pluggy‘: ‘0.13.0‘}, ‘Plugins‘: {‘html‘: ‘2.0.0‘, ‘metadata‘: ‘1.8.0‘, ‘rerunfailures‘: ‘7.0‘}}
rootdir: C:\Users\cale\checkapi\test
plugins: html-2.0.0, metadata-1.8.0, rerunfailures-7.0
collected 3 items

test_gy.py::TestClass::test_one XFAIL [ 33%]
test_gy.py::TestClass::test_two PASSED [ 66%]
test_gy.py::TestClass::test_three PASSED [100%]

======================================================================================================= 2 passed, 1 xfailed in 0.35s =======================================================================================================

 

pytest xfail的使用

原文:https://www.cnblogs.com/pipile/p/12655094.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!