gpt4 book ai didi

python - 如何找到哪些分支没有被测试覆盖?

转载 作者:太空狗 更新时间:2023-10-30 00:44:34 26 4
gpt4 key购买 nike

我正在测量一个小型 Python 应用程序的代码覆盖率。

虽然线路覆盖率是 100%,但分支覆盖率不是。问题是 coverage不会给我任何关于未覆盖的分支位置的指示。

coverage run
--branch
--omit=/usr/lib/python3/dist-packages/*,tests/*
-m unittest discover

返回:

Ran 33 tests in 0.079s

OK
Name Stmts Miss Branch BrMiss Cover Missing
-------------------------------------------------------------
app/__init__ 1 0 0 0 100%
app/file_finder 93 0 40 0 100%
app/zipper 66 0 46 7 94%
-------------------------------------------------------------
TOTAL 160 0 86 7 97%

我希望 Missing 列包含对应于七个缺失分支的行,但那里什么也没有。

我应该如何找到它们?

最佳答案

-m 将仅包括“完整”未命中,而不包括分支未命中。您可以使用命令

coverage html

创建一组 HTML 页面,其中包括所有覆盖范围的突出显示,包括分支未命中。参见例如this example HTML 报告,来自 the documentation .

关于python - 如何找到哪些分支没有被测试覆盖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28326136/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com