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

Visual Studio Code中Test Explorer覆盖率运行图标未显示,求启用方法

问题

我正在使用Python pytest开展测试工作,通过Remote-SSH扩展远程连接Linux Ubuntu服务器。当前Visual Studio Code的Test Explorer中未显示覆盖率运行图标,已附上Testing面板截图及Settings.json配置内容:

VS Code测试选择界面截图

{
"python.analysis.autoImportCompletions": true,
"python.analysis.fixAll": ["source.unusedImports"],  
"editor.defaultFormatter": "charliermarsh.ruff",
"files.exclude": {
    "**/__pycache__": true,
    "**/.cache": true,
    "**/.coverage": true,
    "**/.coverage.*": true,
    "**/.hypothesis": true,
    "**/.mypy_cache": true,
    "**/.nox": true,
    "**/.pytest_cache": true,
    "**/.ruff_cache": true,
    "**/.tox": true
},
"python.testing.pytestEnabled": true
}

请问如何在VS Code界面中启用覆盖率功能?

解决方案
  1. 安装覆盖率依赖包
    在远程Ubuntu服务器的目标Python环境中安装pytest-cov:
pip install pytest-cov
  1. 添加VS Code覆盖率配置
    编辑你的settings.json,加入以下两项配置:
"python.testing.pytestArgs": [
    "--cov",
    "--cov-report=term-missing"
],
"python.testing.coverageEnabled": true
  1. 重载VS Code窗口
    按下Ctrl+Shift+P,执行Reload Window命令,让配置生效。

  2. 验证功能
    重新打开Test Explorer,此时会显示覆盖率运行图标,点击即可生成测试覆盖率报告。

注意:要确保pytest-cov安装在Remote-SSH连接的远程Python环境中,若使用虚拟环境,需先激活对应环境再安装依赖。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 07:30:59