VScode不会计算抛出异常的测试(0/0个测试通过)

huangapple go评论68阅读模式
英文:

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不会计算抛出异常的测试(0/0个测试通过)

更糟糕的是,如果之前的测试通过,它仍然会显示为绿色!"测试结果"选项卡只显示:"测试运行完成!",没有其他输出。如果我以调试模式运行测试,我可以正确地获得输出错误,但测试仍然没有标记为不正确:

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):

VScode不会计算抛出异常的测试(0/0个测试通过)

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:

VScode不会计算抛出异常的测试(0/0个测试通过)

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:

https://github.com/microsoft/vscode-python/pull/21630

huangapple
  • 本文由 发表于 2023年7月18日 02:47:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76707320.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定