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

pytest-cov报错:.coveragerc中[report] exclude_also选项不被识别

问题解决方法

报错原因

当前使用的coverage版本不支持exclude_also配置项,同时配置规则的语法存在错误(缺失引号)。

修复步骤

  1. 替换配置项:将.coveragerc中的exclude_also改为coverage标准支持的exclude_lines(该选项用于指定需要排除覆盖率统计的代码行)
  2. 修正语法错误:把规则行的.__main__.改为'__main__',匹配Python的正确语法

修改后的.coveragerc内容:

[report]
exclude_lines =
    if __name__ == '__main__':
  1. 重新运行你原来的pytest命令即可正常执行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 07:14:51