gpt4 book ai didi

python - 如何使用 nose2 从给定的包中获取覆盖率报告

转载 作者:太空狗 更新时间:2023-10-30 01:28:08 25 4
gpt4 key购买 nike

我想将 nose2 与覆盖率插件一起使用来获得 Python 包的覆盖率,但我很难将其配置为仅覆盖我正在处理的包。该包名为 vimhdl,我的 unittest.cfg 的覆盖部分如下所示:

[coverage]
coverage = vimhdl

对于 nose2,结果不包括包中的所有文件(可能是因为 Coverage.py warning: Module vimhdl was previously imported, but not measured.消息,但我不知道如何修复它)。

此外,当打开给定文件的 HTML 报告时,import logging 和模块的文档字符串等语句被标记为未涵盖。

$ nose2 --with-coverage   -vvv
...
----------------------------------------------------------------------
Ran 5 tests in 0.166s

OK
Coverage.py warning: Module vimhdl was previously imported, but not measured.
---------- coverage: platform linux2, python 2.7.10-final-0 ----------
Name Stmts Miss Cover
---------------------------------------------------------
python/vimhdl/compilers/__init__.py 95 42 56%
python/vimhdl/compilers/ghdl.py 92 41 55%
python/vimhdl/config_parser.py 74 42 43%
python/vimhdl/project_builder.py 269 164 39%
python/vimhdl/source_file.py 126 51 60%
---------------------------------------------------------
TOTAL 656 340 48%

另一方面,使用nosetests,结果包括预期的所有文件。

$ nosetests --with-coverage -vvv

Name Stmts Miss Cover Missing
------------------------------------------------------------
vimhdl.py 5 0 100%
vimhdl/compilers.py 95 11 88% 46-47, 97, 106-108, 131-132, 149-150, 158
vimhdl/compilers/fallback.py 22 7 68% 31-32, 35, 38, 41, 44, 47
vimhdl/compilers/ghdl.py 92 21 77% 91-94, 107-108, 151-172, 182
vimhdl/compilers/msim.py 94 72 23% 49, 52-69, 73-102, 113-124, 128-135, 138-151, 154-159, 163-169, 176-179, 185-190
vimhdl/compilers/xvhdl.py 61 46 25% 38-40, 44-51, 54-76, 87-98, 101-105, 110-126
vimhdl/config.py 69 46 33% 21-22, 55-77, 81-83, 87-91, 95-105, 109-122, 126-135
vimhdl/config_parser.py 74 25 66% 33-34, 45-46, 50, 53-88, 117, 119, 124, 133
vimhdl/exceptions.py 12 4 67% 21, 24, 28, 31
vimhdl/project_builder.py 269 114 58% 23-24, 61-68, 92, 97, 102, 108, 115-121, 131-134, 139-146, 156, 169-170, 182-185, 205-219, 221, 237-273, 278-313, 332-336, 368-371, 373-376, 380-381, 384-385, 393-394, 400, 419-426, 430-431, 455-456, 462-476
vimhdl/source_file.py 126 25 80% 71, 86-87, 168, 172, 174, 176, 178, 197-198, 203-216, 219
vimhdl/static_check.py 104 88 15% 56-112, 119-132, 139-165, 169-188, 191-197, 200
vimhdl/utils.py 8 5 38% 24-28
------------------------------------------------------------
TOTAL 1031 464 55%

如何配置 nose2 覆盖插件以仅覆盖给定模块?

如果有帮助,源代码在 https://github.com/suoto/vim-hdl/tree/unstable 的 github 上。

最佳答案

控制 coverage.py 的最简单方法是使用它来运行测试:

coverage run --source=vimhdl -m nose 

关于python - 如何使用 nose2 从给定的包中获取覆盖率报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34560953/

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