使用py.test + gevent确定测试覆盖率

9

当使用py.test + gevent时,如何获得准确的测试覆盖率报告?

我已经尝试了显而易见的方法,使用pytest-cov插件进行py.test测试,但是当使用gevent时,它会生成不准确的报告


+1 我有完全相同的问题...我尝试使用git+https://github.com/newbrough/coverage.git,它实际上非常好用,但最近pytest抱怨版本太旧并失败了。 - Brian Wylie
1个回答

8
最近修复了关于gevent测试覆盖率的问题,具体可以参考这里
然而,使用coverage>=4时,pytest-cov无法运行。
解决方法之一是不使用pytest-cov插件,而是使用较新版本的coverage.py来运行py.test
首先,安装coverage >= 4并卸载pytest-cov插件。
pip install --pre --upgrade coverage
pip uninstall pytest-cov

将以下设置添加到.coveragerc中:
[run]
concurrency = gevent

然后使用以下命令运行:

coverage run -m py.test

(而不是普通的py.test运行)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接