5

我创建一个这样的覆盖率报告:

nosetests --with-coverage --cover-html

我的.coveragerc文件如下所示:

# .coveragerc to control coverage.py
[run]
branch = True
omit = contextlib, ctypes, ctypes._endian, ctypes.util, filecmp, getpass, sets, subprocess, uuid

[report]
exclude_lines =
    pragma: no cover

但我的报告看起来像这样:

..........
Name             Stmts   Miss Branch BrPart  Cover   Missing
------------------------------------------------------------
abefdb              48     14     13      7    66%   16, 32, 42-43, 47, 57-58, 61-68, 74
ablo                29      2      6      3    86%   44, 66
backup             159     47     61     37    62%   43-51, 54-65, 90, 92, 94, 96, 98, 125, 146-147, 151-158, 178-180, 206, 211, 214, 229, 236-239, 243, 248
contextlib          63     63     14     14     0%   3-154
ctypes             341    341    110    110     0%   4-555
ctypes._endian      35     35     14     14     0%   4-64
ctypes.util        169    169     74     74     0%   4-258
filecmp            160    160     64     64     0%   12-296
getpass            103    103     40     40     0%   18-179
gpiomock            14      0      0      0   100%   
sets               266    266     82     82     0%   57-557
subprocess         641    641    345    345     0%   12-1532
utils              180     52     44     26    65%   24-25, 39-40, 51-53, 62, 67-81, 84-86, 90-92, 96-97, 105, 111-112, 115-116, 134, 144, 147-148, 153-154, 180, 183, 190-194, 206, 211, 224, 227, 230, 236, 251
uuid               293    293    124    124     0%   47-560
------------------------------------------------------------
TOTAL             2501   2186    991    940    10%   
----------------------------------------------------------------------
Ran 10 tests in 7.730s

OK

如何从报告中删除覆盖率为 0% 的标准库包?显然,将它们列出来omit并不像我期望的那样工作......

4

1 回答 1

6

omit必须是目录/文件名模式的列表,例如:

omit = /usr/*, /System/*
于 2013-08-31T10:37:02.333 回答