简体   繁体   English

如何使用setup.cfg正确限制nosetests中的xcoverage包覆盖?

[英]How do you properly restrict xcoverage package coverage in nosetests using setup.cfg?

I've configured it so my simple unit test passes. 我已配置它,所以我的简单单元测试通过。 But nosexunit.xml is reporting on test lib files. 但是nosexunit.xml报告了测试lib文件。 Partial output: 部分输出:

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

The project is split up into different modules that need to be tested independently. 该项目分为不同的模块,需要独立测试。 I'm focusing on the backend module at present. 我目前专注于后端模块。 I want to restrict coverage to the lib package. 我想限制lib包的覆盖范围。 A sample of the project tree: 项目树的示例:

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

I'm running the tests from the dir named backend: 我正在从名为backend的目录运行测试:

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

Nosetests is configured in setup.cfg as follows 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

I've got a feeling one of the path settings is off. 我感觉其中一个路径设置已关闭。 I'm assuming the where and cover-package settings are relative to the location of setup.py (also where I'm running the test) and include is relative to where . 我假设wherecover-package设置是相对于setup.py的位置(也是我正在运行测试的地方)并且include是相对于where

Nosetests documentation wasn't much help. Nosetests文档没有多大帮助。 I hope someone can set me straight here. 我希望有人可以直截了当我。

It turns out that I had this configured correctly after all. 事实证明,毕竟我配置正确。 The problem seems to be that, for my overly simplified smoke test, I wasn't actually importing anything from the module to which I restricted coverage. 问题似乎是,对于我过度简化的烟雾测试,我实际上并没有从我限制覆盖范围的模块中导入任何东西。

Apparently, in this case, when coverage is nil, rather than report that boring fact, nosexcoverage or nosetests decides to give you a coverage report about a bunch of other stuff instead. 显然,在这种情况下,当覆盖范围为零时,而不是报告无聊的事实,nosexcoverage或nosetests决定给你一个关于其他东西的报道报告。

By adding an import statement for the module I wanted covered, I got the proper coverage report: 通过为我想要覆盖的模块添加import语句,我得到了正确的覆盖报告:

----------------------------------------------------------------------
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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM