用于在python中显示coverage的命令行选项

时间:2013-11-23 10:03:47

标签: python unit-testing nose test-coverage python-coverage

当我从终端使用nose来显示覆盖范围的测试结果时,我得到错误并且缺少实际覆盖的行

$ 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?我站在同一个目录中!

1 个答案:

答案 0 :(得分:1)

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

测试模块必须有

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

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

之前我刚刚unittest.main()