简体   繁体   English

Visual Studio 代码的 Coverage-Gutter 扩展未显示 python3 项目中的行覆盖率

[英]Coverage-Gutter extension for visual studio code is not showing line coverage in python3 project

I installed coverage gutter extension for visual studio code but is not showing the line coverage, when I press Coverage Gutter display coverage or press the "watch" option in the footer it says "Could not find coverage file"我为 Visual Studio 代码安装了 Coverage Gutter 扩展,但没有显示线路覆盖,当我按下 Coverage Gutter 显示覆盖或按下页脚中的“watch”选项时,它显示“找不到覆盖文件”

In this github doesn't mention anything about configuring a coverage file or anything在这个 github 没有提到任何关于配置覆盖文件或任何东西

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

this is a code of one of my test I'm using unittest这是我正在使用的一项测试的代码 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(""))

The error that I'm getting is a message that says "Could not find a Coverage file!"我收到的错误是一条消息,上面写着“找不到覆盖文件!”

By default, Coverage Gutter expectes to read the coverage data from a cov.xml file in the root of your project which contains the coverage data.默认情况下,Coverage Gutter 期望从项目根目录中包含覆盖数据的cov.xml文件中读取覆盖数据。

Eg run this in the root folder of the project.例如,在项目的根文件夹中运行它。 It will run all tests within the test/ folder and will create a cov.xml它将运行 test/ 文件夹中的所有测试,并创建一个 cov.xml

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

Of course you need to have the correct python plugins installed, which are "pytest", "coverage" and "pytest-cov" in this case.当然,您需要安装正确的 python 插件,在这种情况下是“pytest”、“coverage”和“pytest-cov”。

You can also adjust the default filename which is used in the extension settings of coverage gutter within visual studio to sth.您还可以将 Visual Studio 中覆盖范围的扩展设置中使用的默认文件名调整为 sth。 like mypersonalcovfile.xml if you like.喜欢 mypersonalcovfile.xml 如果你喜欢。

It looks like Coverage Gutters will read an lcov file or a.xml file.看起来 Coverage Gutters 将读取 lcov 文件或 a.xml 文件。 Have you generated a coverage.py xml file?您是否生成了coverage.py xml 文件? For example, with coverage xml .例如, coverage xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM