鼻子测试覆盖率许可错误

时间:2011-03-31 10:40:01

标签: python code-coverage nosetests

我今天开始使用测试,一切正常,直到我尝试:

nosetests --with-coverage --cover-html --cover-html-dir=/tmp/cache抛出一个权限被拒绝的错误,我不明白它为什么要写入标准库包:

Traceback (most recent call last):
  File "/usr/bin/nosetests", line 8, in <module>
    load_entry_point('nose==0.11.1', 'console_scripts', 'nosetests')()
  File "/usr/lib/pymodules/python2.6/nose/core.py", line 113, in __init__
    argv=argv, testRunner=testRunner, testLoader=testLoader)
  File "/usr/lib/python2.6/unittest.py", line 817, in __init__
    self.runTests()
  File "/usr/lib/pymodules/python2.6/nose/core.py", line 192, in runTests
    result = self.testRunner.run(self.test)
  File "/usr/lib/pymodules/python2.6/nose/core.py", line 63, in run
    result.printErrors()
  File "/usr/lib/pymodules/python2.6/nose/result.py", line 88, in printErrors
    self.config.plugins.report(self.stream)
  File "/usr/lib/pymodules/python2.6/nose/plugins/manager.py", line 82, in __call__
    return self.call(*arg, **kw)
  File "/usr/lib/pymodules/python2.6/nose/plugins/manager.py", line 150, in simple
    result = meth(*arg, **kw)
  File "/usr/lib/pymodules/python2.6/nose/plugins/cover.py", line 168, in report
    coverage.annotate(files.values())
  File "/usr/lib/python2.6/dist-packages/coverage.py", line 995, in annotate
    return the_coverage.annotate(*args, **kw)
  File "/usr/lib/python2.6/dist-packages/coverage.py", line 906, in annotate
    self.annotate_file(filename, statements, excluded, missing, directory)
  File "/usr/lib/python2.6/dist-packages/coverage.py", line 921, in annotate_file
    dest = open(dest_file, 'w')
IOError: [Errno 13] Permission denied: '/usr/lib/python2.6/email/iterators.py,cover'

2 个答案:

答案 0 :(得分:4)

鼻子--cover-html开关已过时。如果你先运行鼻子,然后直接使用coverage来生成HTML:

,你会对结果更满意
$ nosetests --with-coverage
$ coverage html

然后打开htmlcov / index.html

答案 1 :(得分:0)

我发现我可以使用--cover-package=参数和我想要覆盖的包的名称。