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

VSCode无法识别Python unittest测试的配置问题及后续疑问

VSCode Python unittest 识别异常问题

问题详情

  • Python unittest测试在PowerShell中可正常执行,但VSCode无法正确识别测试用例
  • 已尝试的排查操作:
    • 在测试目录中添加__init__.py文件
    • 通过命令面板执行「配置测试」→ unittest → .root → test_,无任何响应
    • 卸载并重新安装Python扩展后重复上述配置流程
  • 当前settings.json配置内容:
{
   "python.testing.unittestArgs": [
       "-v",
       "-s",
       "./Tutto",
       "-p",
       "*test*.py"
   ],
   "python.testing.pytestEnabled": false,
   "python.testing.unittestEnabled": true,
   "python.testing.pytestArgs": [
       "."
   ]
}
  • 项目结构:Tutto为项目根目录,业务脚本存放于src文件夹,测试文件位于src/test目录下(包含test_blabla.py和__init__.py)
  • 执行上述操作后无报错,但VSCode始终无法找到测试用例

临时解决方案及遗留问题

  • 临时修复方式:将settings.json中python.testing.unittestArgs里的"./Tutto"替换为测试文件夹的完整绝对路径后,VSCode测试扩展可正常识别测试用例
  • 仍存在的问题:
    1. 代码编辑器中无「运行测试」和「调试测试」的功能选项
    2. 该配置会固定指向Tutto项目的测试路径,切换到其他带测试文件夹的项目时,将路径改为"."无法正常工作

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 11:42:08