pytest多重?cái)嘌缘膶?shí)現(xiàn)
當(dāng)我們寫用例斷言時(shí),往往一個(gè)斷言結(jié)果是不夠的,所以需要加入多重?cái)嘌?,而多重?cái)嘌?,?dāng)斷言中間出現(xiàn)斷言結(jié)果False時(shí),會中斷后續(xù)的斷言執(zhí)行,會導(dǎo)致測試用例執(zhí)行結(jié)果的準(zhǔn)確性不高
使用pytest框架的插件pytest-assume, 實(shí)現(xiàn)用例執(zhí)行時(shí),其中一個(gè)斷言失敗后,執(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'])
我們很容易在以下信息中找出相應(yīng)的日志信息:
在行有E標(biāo)記的信息中,我們可以清晰看到提示 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 ====================
進(jìn)程已結(jié)束,退出代碼 0
到此這篇關(guān)于pytest多重?cái)嘌缘膶?shí)現(xiàn)的文章就介紹到這了,更多相關(guān)pytest多重?cái)嘌詢?nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
將不規(guī)則的Python多維數(shù)組拉平到一維的方法實(shí)現(xiàn)
這篇文章主要介紹了將不規(guī)則的Python多維數(shù)組拉平到一維的方法實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01python標(biāo)準(zhǔn)日志模塊logging的使用方法
python的標(biāo)準(zhǔn)庫里的日志系統(tǒng)從Python2.3開始支持。只要import logging這個(gè)模塊即可使用。2013-11-11Pycharm項(xiàng)目代碼同步到Gitee的圖文步驟
本文主要介紹了Pycharm項(xiàng)目代碼同步到Gitee的圖文步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02Python產(chǎn)生batch數(shù)據(jù)的操作
這篇文章主要介紹了Python產(chǎn)生batch數(shù)據(jù)的操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-03-03Python使用bcrypt?或?Passlib?對系統(tǒng)用戶密碼進(jìn)行哈希和驗(yàn)證處理操作
在Python?開發(fā)中,我們可以引入bcrypt?或?Passlib?對系統(tǒng)用戶密碼進(jìn)行哈希和驗(yàn)證處理,以及介紹使用其他類庫實(shí)現(xiàn)常規(guī)加解密處理操作,需要的朋友可以參考下2024-08-08