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

如何让interrogate pre-commit在检查通过时仍输出覆盖率结果?

解决Interrogate作为Pre-Commit警告而非失败检查的方法

有两种可行方式实现需求:既让Interrogate输出完整的覆盖率统计结果,又不会导致Pre-Commit提交流程失败。

方案一:调整Interrogate参数(推荐)

直接在Pre-Commit钩子配置中给Interrogate添加两个关键参数:

  • --fail-under=0:强制Interrogate始终返回成功状态,无论实际文档字符串覆盖率高低
  • --verbose:让Interrogate输出详细的覆盖率信息,包括未添加文档字符串的文件、函数、类等明细

修改你的.pre-commit-config.yaml配置如下:

repos:
-   repo: https://github.com/econchick/interrogate
    rev: v1.5.0  # 替换为你实际使用的版本号
    hooks:
    -   id: interrogate
        args:
            - --fail-under=0
            - --verbose
            # 若项目用pyproject.toml管理Interrogate配置,添加此行
            - --config=pyproject.toml

方案二:用Shell命令强制返回成功

通过自定义本地钩子,用Shell命令包装Interrogate,忽略其原始退出码,强制返回0以确保Pre-Commit流程通过:

repos:
-   repo: local
    hooks:
    -   id: interrogate-warning
        name: Interrogate (verbose warning)
        entry: bash -c 'interrogate --verbose --config=pyproject.toml || true'
        language: system
        types: [python]

这种方式下,即使Interrogate原本因覆盖率不足触发报错,Shell命令也会返回成功状态,同时完整保留所有输出内容。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 16:03:10