【发布时间】:2020-09-05 17:35:47
【问题描述】:
有很多类似的问题(例如1、2、3、4、5、6,...),但没有一个问题完全组合在一起(即 unittest 发现在 shell 提示符下工作),这些问题的解决方案对我不起作用。
当我在 Visual Studio Code 中运行 Python: Discover Tests 时出现错误
未发现测试,请检查测试的配置设置。
我的 settings.json 文件如下所示
{
"python.testing.unittestArgs": [
"--verbose",
"--start-directory",
"./preprocessing/",
"--pattern",
"test_*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": true
}
但我知道单元测试是可发现的,因为如果我从项目的根目录运行此命令,所有测试都会被发现并运行:
python -m unittest discover --verbose --start-directory "./preprocessing/" --pattern "test_*.py"
我的测试显然可以被 Python 的 unittest 框架发现,但 VS Code 没有找到它们。我该如何解决这个问题?
【问题讨论】:
-
首先,注释所有导入语句并发现测试。如果可行,请检查您的导入语句。
标签: python visual-studio-code python-unittest