英文:
VScode does not count tests that throw exceptions (0/0 tests passed)
问题
我的开发环境是:
vscode 1.80.1
python 3.10
使用vscode的python扩展 v2023.12.0
我的测试文件:
import unittest
class MyTestCase(unittest.TestCase):
def test_say_hello(self) -> None:
raise Exception("test")
我的vscode设置:
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./runner",
"-p",
"test_*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true,
}
我希望当我运行测试时,会因为引发的异常而显示错误,但实际上没有。相反,在vscode的"测试"选项卡中显示(0/0 通过的测试):
更糟糕的是,如果之前的测试通过,它仍然会显示为绿色!"测试结果"选项卡只显示:"测试运行完成!",没有其他输出。如果我以调试模式运行测试,我可以正确地获得输出错误,但测试仍然没有标记为不正确:
在vscode外部手动运行单元测试会正确显示错误(就像调试模式中的输出一样)。
那么,我如何让vscode显示我的失败测试?
英文:
My dev environment is:
vscode 1.80.1
python 3.10
using the python extension for vscode v2023.12.0
My test file:
import unittest
class MyTestCase(unittest.TestCase):
def test_say_hello(self) -> None:
raise Exception("test")
My vscode settings:
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./runner",
"-p",
"test_*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true,
}
I would expect that when I run the test to show an error because of the raised exception, but it does not. Instead, the "testing" tab in vscode shows (0/0 tests passed):
Worst, if the tests was previously passing it would still show up with a green mark! The "Tests Results" tab simply shows: "Finished running tests!" with no other outputs. If I run the test in debug mode, I correctly get the output error, but the tests is still not marked as incorrect:
Running unittests manually outside vscode correctly display the error (just like the output in debug mode).
So how do I get vscode to display my failing tests?
答案1
得分: 0
我发现这是一个已知问题,已经有一个修复程序推送到主分支,但它还没有出现在实时版本中:
https://github.com/microsoft/vscode-python/pull/21630
英文:
I found out that it is a known issue and there is already a fix pushed to the main branch, but it is not present in the live version yet:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论