1

当我从终端使用鼻子显示覆盖范围的测试结果时,我得到错误和缺失的行,这些行实际上被覆盖了

$ python -m nose.core test_utils.py -s --with-coverage

======================================================================
ERROR: Failure: AttributeError ('module' object has no attribute 'test_utils')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/nose/loader.py", line 413, in loadTestsFromName
    addr.filename, addr.module)
  File "/Library/Python/2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/Library/Python/2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/Development/python/slideShow/tests/test_utils.py", line 50, in <module>
    unittest.main()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 94, in __init__
    self.parseArgs(argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 149, in parseArgs
    self.createTests()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 158, in createTests
    self.module)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 128, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 100, in loadTestsFromName
    parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'test_utils'

Name      Stmts   Miss  Cover   Missing
---------------------------------------
PyQt4         0      0   100%   
getopt      103    103     0%   34-210
mox         597    597     0%   17-1898
stubout      50     50     0%   17-142
utils        23     16    30%   8-10, 13-20, 23, 26-30

怎么找不到test_utils?我站在同一个目录下!

4

1 回答 1

1

好吧,在故障排除时我得到了答案,

测试模块必须有

if __name__ == '__main__': unittest.main()

为了python -m nose.core test_utils.TestUtils --with-coverage工作

早些时候我刚刚unittest.main()

于 2013-11-23T11:19:41.337 回答