欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

pytest多重斷言的實現(xiàn)

 更新時間:2023年02月14日 09:50:45   作者:leslie0727  
本文主要介紹了pytest多重斷言的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

當我們寫用例斷言時,往往一個斷言結果是不夠的,所以需要加入多重斷言,而多重斷言,當斷言中間出現(xiàn)斷言結果False時,會中斷后續(xù)的斷言執(zhí)行,會導致測試用例執(zhí)行結果的準確性不高
使用pytest框架的插件pytest-assume, 實現(xiàn)用例執(zhí)行時,其中一個斷言失敗后,執(zhí)行后續(xù)的斷言

安裝:pip install pytest-assume

以下為使用示例:

import pytest
from pytest_assume.plugin import assume
  
class TestTwo:
    def test001(self):
        with assume:
            assert True
        with assume:
            assert 1 == 2
 
    def test002(self):
        assert 1 == 1
 
if __name__ == '__main__':
    pytest.main(['-v', 'test_002.py'])

我們很容易在以下信息中找出相應的日志信息:

在行有E標記的信息中,我們可以清晰看到提示 pytest_assume.plugin.FailedAssumption: 1 Failed Assumptions

collecting ... collected 2 items
 
test_002.py::TestTwo::test001 FAILED                                     [ 50%]
test_002.py::TestTwo::test002 PASSED                                     [100%]
 
================================== FAILURES ===================================
_______________________________ TestTwo.test001 _______________________________
 
self = <test_002.TestTwo object at 0x000001B24B284C40>
 
    def test001(self):
        with assume:
            assert True
        with assume:
>           assert 1 == 2
E           pytest_assume.plugin.FailedAssumption: 
E           1 Failed Assumptions:
E           
E           test_002.py:10: AssumptionFailure
E           >>    assert 1 == 2
E           AssertionError: assert 1 == 2
E             +1
E             -2
 
test_002.py:10: FailedAssumption
============================== warnings summary ===============================
D:\Python3.9.10\lib\site-packages\_pytest\config\__init__.py:1126
  D:\Python3.9.10\lib\site-packages\_pytest\config\__init__.py:1126: PytestAssertRewriteWarning: Module already imported so cannot be rewritten: pytest_assume
    self._mark_plugins_for_rewrite(hook)
 
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ===========================
FAILED test_002.py::TestTwo::test001 - pytest_assume.plugin.FailedAssumption: 
=================== 1 failed, 1 passed, 1 warning in 0.19s ====================
 
進程已結束,退出代碼 0

到此這篇關于pytest多重斷言的實現(xiàn)的文章就介紹到這了,更多相關pytest多重斷言內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論