1

I'm trying to get my tests to report missing lines and branches. I've configured nose2 and coverage to produce line and branch coverage, and as far as I can tell I have set the coverage config correctly to give me the missing lines and branches. However I can't get coverage to give me missing column when run under nose2, but I can if I run it directly.


Consider the following setup in my project directory.

my_module/
    __init__.py
    main.py
tests/
    test_a_thing.py
unittest.cfg
.coveragerc

contents of .coveragerc

[run]
branch = True

[report]
show_missing = True

contents of unittest.cfg

[coverage]
always-on = True
coverage = my_module
coverage-config = .coveragerc

the output of my nose2 command

(example_venv) andy@batman[11:30:53]:/space/test_example$ python -m nose2 -c unittest.cfg --no-user-config
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
----------- coverage: platform linux, python 3.5.2-final-0 -----------
Name                    Stmts   Miss Branch BrPart  Cover
---------------------------------------------------------
my_module/__init__.py       0      0      0      0   100%
my_module/main.py           4      1      2      1    67%
---------------------------------------------------------
TOTAL                       4      1      2      1    67%

As you can see, it has given me Branch cover, but not told me the missing branches.

If I simply run coverage report (on the produced .coverage file that is left behind after running nose)

(example_venv) andy@batman[11:34:15]:/space/test_example$ coverage report
Name                    Stmts   Miss Branch BrPart  Cover   Missing
-------------------------------------------------------------------
my_module/__init__.py       0      0      0      0   100%
my_module/main.py           4      1      2      1    67%   3, 2->3
-------------------------------------------------------------------
TOTAL                       4      1      2      1    67%

You can see that coverage has given me the missing branches.


I can tell that coverage is picking up the .coveragerc when run under nose2, because if I remove the branch = True line under the [run] section in .coveragerc, then the branch coverage stats disappear from the report when run under nose.


Am I missing something extra I'm supposed to have done to get this show_missing config to get passed to coverage when it is run under nose2?

versions installed

cov-core==1.15.0
coverage==4.3.4
nose2==0.6.5
4

1 回答 1

1

tl;博士 - 必须添加coverage-report = term-missing到(或其他文件)中的[coverage]部分。为了传递给unittest.cfg--config [CONFIG], -c [CONFIG]nose2Cov-Coreshow_missing = Truecoverage


更长的解释:

coverage report在命令行上运行时,除非在命令行参数中被覆盖,否则show_missing将传递给coverage.coverage()* 。None

但是nose2使用cov-core,它将作为or传递show_missingcoverage.coverage()* in 。基于以下逻辑:cov_core.CovController.summary()TrueFalse

if 'term' in self.cov_report or 'term-missing' in self.cov_report:
    show_missing = 'term-missing' in self.cov_report
    self.cov.report(show_missing=show_missing, ignore_errors=True, file=stream)

cov_report那个coverage-report配置是​​在nose2.

所以这是我的困惑,因为我试图使用coverage's 配置来产生缺失的行/分支(在对术语进行报告时,有一个额外的标志show_missing),当Cov-Core将它们视为单独的报告时(或者报告term以获得简单的覆盖,或者term-missing获得简单的覆盖范围+缺失的行)。

Cov-Core因此,当大多数其他位(包括/排除一个分支覆盖)仍然由的配置驱动时,不要让自己被决定覆盖的这一点覆盖行为所coverage困扰。


*coverage.coverage() 是一个向后兼容性调整,实际上是coverage.control.Coverage() 的导入(在coverage/__init__.py 中)

于 2017-02-03T11:24:57.120 回答