3

我已经对其进行了配置,因此我的简单单元测试通过了。但是nosexunit.xml 正在报告测试库文件。部分输出:

nosexcover-1.0.7-py2.6.egg/nosexcover/nosexcover    25     24     4%   5-41, 46-56
test/unit/test_setup                                13      0   100%   

该项目分为不同的模块,需要独立测试。我目前专注于后端模块。我想限制对 lib 包的覆盖。项目树的示例:

project
\-- backend     # <-- module I'm testing
    \-- lib     # <-- what I want to cover
    \-- test
       \-- unit/test_setup.py       # <-- test I'm running
    \-- setup.py
    \-- setup.cfg
\--reporting
    \-- setup.py
    \-- setup.cfg

我正在从名为 backend 的目录运行测试:

project/backend$ python setup.py nosetests -s --tests=unit/test_setup.py

nosetests 在 setup.cfg 中配置如下

[nosetests]
# locating tests
where=./test
include=^unit.*

# coverage
cover-package=lib
cover-html=1
cover-html-dir=htmlcov
with-xcoverage=1
xcoverage-file=coverage.xml
with-xunit=1
xunit-file=nosexunit.xml
cover-erase=1

我感觉其中一个路径设置已关闭。我假设whereandcover-package设置相对于setup.py(也是我运行测试的位置)的位置,并且include相对于where.

Nosetests 文档没有太大帮助。我希望有人可以让我在这里直截了当。

4

1 回答 1

0

事实证明,我毕竟正确配置了这个。问题似乎是,对于我过于简化的烟雾测试,我实际上并没有从我限制覆盖的模块中导入任何东西。

显然,在这种情况下,当覆盖率为零时,nosexcoverage 或 nosetests 决定为您提供有关一堆其他内容的覆盖率报告,而不是报告那个无聊的事实。

通过为我想要覆盖的模块添加导入语句,我得到了正确的覆盖率报告:

----------------------------------------------------------------------
XML: nosexunit.xml
Name        Stmts   Miss  Cover   Missing
-----------------------------------------
lib             0      0   100%   
lib.blank       1      0   100%   
-----------------------------------------
TOTAL           1      0   100%   
----------------------------------------------------------------------
Ran 2 tests in 0.008s
于 2012-03-13T15:28:58.667 回答