截止到今天,测试发现对我来说不再起作用,设置起来已经很棘手,而且我似乎无法修复。
文件夹结构:
src /-所有代码
测试/-所有测试
.env /-virtualenv
.envFile-
(src或测试中没有__init__.py文件)
Python扩展设置:
"python.autoComplete.addBrackets": true,
"python.autoComplete.extraPaths": [
"${workspaceRoot}/src"
],
"python.envFile": "${workspaceFolder}/.envFile",
"python.pythonPath": "${workspaceFolder}/.env/bin/python",
"python.unitTest.pyTestArgs": [
"-v", // increase verbosity
"-l", // show locals in tracebacks
"-x", // exit instantly on first error or failed test
"--ff", // run all tests but run the last failures first
"--color=yes" // color terminal output (yes/no/auto)
],
"python.unitTest.pyTestEnabled": true,
"python.unitTest.unittestArgs": [
"*test*.py",
"-p",
"-s",
"-v",
"."
],
"python.venvFolders": [
".env"
],
"python.workspaceSymbols.exclusionPatterns": [
"**/.env/",
"**/site-packages/**",
"_build"
],
.envFile
= PYTHONPATH=./src/
运行“发现所有测试”时的Python测试日志:
[1m============================= test session starts ==============================[0m
platform darwin -- Python 3.6.4, pytest-3.2.1, py-1.4.34, pluggy-0.4.0
rootdir: [redacted]/src, inifile:
plugins: cov-2.5.1
collected 0 items
[33m[1m========================= no tests ran in 0.05 seconds =========================[0m
最后:
PYTHONPATH=./src py.test tests --collect-only
======================================================================================================================== test session starts ========================================================================================================================
platform darwin -- Python 3.6.4, pytest-3.2.1, py-1.4.34, pluggy-0.4.0
rootdir: [redacted, note no src], inifile:
plugins: cov-2.5.1
collected 225 items
答案 0 :(得分:0)
我建议将Python扩展降级为2018.5.0。 GitHub上有多个问题描述运行测试(https://github.com/Microsoft/vscode-python/issues)的问题。
答案 1 :(得分:0)
Don Jayamanne本人已在此Github问题中回答: https://github.com/Microsoft/vscode-python/issues/2047
答案 2 :(得分:0)
某些人可能的解决方法:
遇到此问题时,我的解决方法是查看Python测试日志(请参见下文),并注意到有关ImportError的错误。我修复了导入错误,然后在几秒钟后自动发现了测试。
更多信息:要进入Python测试日志,请转到左侧边栏中的“测试”>运行所有测试(图标具有播放按钮和两个烧杯),并且在运行该测试时,您应该(希望)看到两个弹出窗口通知:
单击“查看输出”以获取第二个。