zoukankan      html  css  js  c++  java
  • pytest xfail的使用

    @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:Userscalecheckapi est>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:usersipharmacarepython37python.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:Userscalecheckapi est
    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:Userscalecheckapi est>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:usersipharmacarepython37python.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:Userscalecheckapi est
    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 =======================================================================================================

  • 相关阅读:
    【达梦公开课】视频汇总
    【.NET框架】—— MVC5+EF6实体——连表视图查询(七)
    【.NET框架】—— MVC5+EF6实体模型自动创建(七)
    【.NET框架】—— MVC5+EF进行CRUD(六)
    SqlServer必知必会之个人小笔记
    【.NET框架】—— ASP.NET MVC5路由基础(五)
    【.NET框架】—— MVC5 与jQuery库(四)
    【.NET框架】—— ASP.NET MVC数据验证注解(三)
    面试时写不出排序算法?看这篇就够了——转载《java那些事》微信公众号
    【.NET框架】—— ASP.NET MVC5 表单和HTML辅助(二)
  • 原文地址:https://www.cnblogs.com/pipile/p/12655094.html
Copyright © 2011-2022 走看看