You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在pytest报告中隐藏已跳过测试的数量信息

隐藏pytest汇总报告中“已跳过测试数量”的快捷方法

你不需要复杂定制TestingReport,有两个简洁的实现方式:

方法一:通过conftest.py钩子精准移除

在项目根目录创建/修改conftest.py,添加以下代码:

def pytest_terminal_summary(terminalreporter, exitstatus, config):
    # 过滤掉包含deselected的汇总行
    terminalreporter.report_sections = [
        sec for sec in terminalreporter.report_sections
        if "deselected" not in sec[0]
    ]

这段代码利用pytest的pytest_terminal_summary钩子,在生成终端报告时直接移除包含“deselected”的统计条目,无需修改核心报告类,属于轻量快捷的定制方案。

方法二:使用安静模式简化输出(折中方案)

如果只是想快速减少冗余输出,可直接使用命令行参数-q(安静模式):

pytest -q -m "你的标签"

安静模式会大幅压缩报告内容,虽然不会精准只移除deselected条目,但能快速让报告更简洁,适合日常快速执行测试场景。

内容的提问来源于stack exchange,提问作者Meru

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 09:40:28