python - 停止 pytest 错误但不失败
问题描述
Pytest 报告error
是否在初始化夹具中断言失败,以及fail
在初始化夹具运行后测试是否失败。
要使测试套件在错误或失败时停止,可以使用以下标志:
-x, --exitfirst exit instantly on first error or failed test.
如何在第一个错误后停止测试套件,但如果出现故障则继续运行?
解决方案
这应该不难实现自己。一个最小的例子(未经测试):
# conftest.py
from _pytest.main import Failed
def pytest_runtest_logreport(report):
if report.failed and report.when in ('setup', 'teardown'):
raise Failed()
这将在测试失败 ( report.failed and report.when == 'call'
) 时继续,但在设置/拆卸错误时停止。
推荐阅读
- sql - 如何替换特定单词
- kamailio - 在两个 Kamailio 服务器之间转发 SIP 请求
- android - 应用程序在后台时的参与时间计算
- python - PIL中“P”和“L”模式下的图像有什么区别?
- java - event.consume() 方法在 javafx 中不起作用
- php - CI中的多个mysql查询
- javascript - javascript中的await关键字会减慢应用程序的速度吗?
- amazon-web-services - 如何在不影响数据的情况下删除 DynamoDb 表中的范围键列?
- php - 如何在不使用 php artisan 的情况下创建 Laravel 开发服务器
- php - 如何在 Wordpress 的其他地方显示产品的价格