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 =======================================================================================================

  • 相关阅读:
    linux(fedora) 下dvwa 建筑环境
    【ThinkingInC++】2、输入和输出流
    Caused by: java.lang.ClassNotFoundException: javax.transaction.TransactionManager
    SpringMVC注释启用
    XML wsdl soap xslt xsl ide
    一个解析RTSP 的URL函数
    PHP:header()函数
    jquery实现鼠标焦点十字效果
    拼出漂亮的表格
    Oracle中如何插入特殊字符:& 和 ' (多种解决方案)
  • 原文地址:https://www.cnblogs.com/pipile/p/12655094.html
Copyright © 2011-2022 走看看