網站首頁 編程語言 正文
當我們寫用例斷言時,往往一個斷言結果是不夠的,所以需要加入多重斷言,而多重斷言,當斷言中間出現(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
原文鏈接:https://blog.csdn.net/weixin_43877527/article/details/128534270
相關推薦
- 2022-08-15 C語言排序算法實現(xiàn)
- 2022-10-24 Python?NumPy教程之遍歷數(shù)組詳解_python
- 2022-07-22 URLClassLoader加載Class時的類初始化問題
- 2022-06-12 C語言?智能指針?shared_ptr?和?weak_ptr_C 語言
- 2022-06-28 python神經網絡學習利用PyTorch進行回歸運算_python
- 2022-09-04 Go語言流程控制語句_Golang
- 2022-12-27 一文帶你了解Go語言標準庫strings的常用函數(shù)和方法_Golang
- 2023-03-17 Android?ViewModel與Lifecycles和LiveData組件用法詳細講解_Andr
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支