我写了一个“包” - 我指的是在它的__init__.py
目录 - 所谓的ardid
:什么是鼻子测试套件?
(master)[email protected][ardid]> ls
analysis.py ardid.sh __init__.pyc plot_support.py utils.py
analysis.pyc goals.py k_12.png plot_support.pyc utils.pyc
ardid.py goals.pyc plot_ardid.py results/
ardid.pyc __init__.py plot_ardid.pyc tests/
正如你所看到的,包包含以下模块
analysis
ardid
goals
plot_ardid
plot_support
utils
以及测试模块在目录tests
。
(__init__.py
为空)
然而,当我运行nosetests
与--cover-package=ardid
,输出显示覆盖只对少数的ardid
的模块(具体地说ardid
,goals
,和utils
):
(master)[email protected][ardid]> nosetests tests -s --cover-package=ardid --with-coverage
...............
Name Stmts Miss Cover Missing
----------------------------------------------
ardid.py 0 0 100%
ardid/ardid.py 108 54 50% 105-254
ardid/goals.py 42 38 10% 52-87, 102-161
ardid/utils.py 437 366 16% 23-26, 30-71, 78, 83-89, 108-110, 113-140, 142-146, 165-166, 168-183, 186-218, 223-285, 288-324, 344, 357-427, 438-441, 443-444, 446-468, 475-480, 483-496, 499, 508-509, 512-513, 516-524, 532, 545-548, 559, 571, 575-576, 581-582, 594-605, 614-615, 618-1018
----------------------------------------------
TOTAL 587 458 22%
----------------------------------------------------------------------
Ran 15 tests in 11.454s
OK
这是为什么?
请注意,这是不是这种情况,这些是我必须测试的唯一模块:
(master)[email protected][ardid]> ls tests/
test_plot_support.py test_plot_support.pyc test_utils.py test_utils.pyc
什么是真正的是,ardid
模块导入goals
和utils
,但不会导入其他模块。这是什么导致nosetests
只能检测到goals
和utils
(除了ardid
)?为什么会这样?
我认为答案可能与我在我的测试模块中导入软件包模块的方式有关。因为ardid
模块具有相同的名称,包装,我必须用
from ardid import ardid
导入(如果我只需拨打
import ardid
包将被导入。)
我输入的其他模块,例如,
import utils
是否有覆盖排除文件的测试? '__init __。py'中是什么? – jonrsharpe
如果你在*目录结构中“上”*一级,并在那里运行相同的命令,会发生什么? – jonrsharpe
考虑转型使得'tests'和'ardid'目录是在*同级别*,另一个字典中(你也可以拨打'ardid')。然后从* that *目录运行测试。 – jonrsharpe