【问题标题】:Coverage-Gutter extension for visual studio code is not showing line coverage in python3 projectVisual Studio 代码的 Coverage-Gutter 扩展未显示 python3 项目中的行覆盖率
【发布时间】:2020-03-02 01:56:58
【问题描述】:

我为 Visual Studio 代码安装了 Coverage Gutter 扩展,但没有显示线路覆盖,当我按 Coverage Gutter 显示覆盖或按页脚中的“观看”选项时,它显示“找不到覆盖文件”

在这个 github 中没有提到任何关于配置覆盖文件或任何内容的内容

https://github.com/ryanluker/vscode-coverage-gutters

这是我正在使用 unittest 的测试代码之一

class Test_SetValuesService(unittest.TestCase):

def test_given_none_property_when_checking_if_none_return_empty(self):
    #ASSERT
    self.assertEqual("&nbsp", setValuesService.check_if_json_property_is_null(""))

我收到的错误消息是“找不到 Coverage 文件!”

【问题讨论】:

    标签: python python-3.x visual-studio-code python-unittest coverage.py


    【解决方案1】:

    看起来 Coverage Gutters 将读取 lcov 文件或 .xml 文件。您是否生成了coverage.py xml 文件?例如,coverage xml

    【讨论】:

      【解决方案2】:

      默认情况下,Coverage Gutter 会从项目根目录中包含覆盖数据的 cov.xml 文件中读取覆盖数据。

      例如在项目的根文件夹中运行它。它将运行 test/ 文件夹中的所有测试并创建一个 cov.xml

      pytest --cov=. tests/ --cov-report xml:cov.xml
      

      当然你需要安装正确的python插件,在这种情况下是“pytest”、“coverage”和“pytest-cov”。

      您还可以将 Visual Studio 中 Coverage Gutter 扩展设置中使用的默认文件名调整为 sth。如果你愿意,喜欢 mypersonalcovfile.xml。

      【讨论】:

        猜你喜欢
        • 2019-04-03
        • 1970-01-01
        • 2017-08-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多