使用py.test和gevent确定测试覆盖率
如何在使用 py.test
和 gevent
时获取准确的测试覆盖率报告?
我已经尝试了很明显的方法,使用 py.test
的 pytest-cov
插件,但它在使用 gevent
时会 生成不准确的报告。
1 个回答
8
最近,gevent 的覆盖率问题在 coveragepy
中得到了修复。
不过,pytest-cov
在使用 coverage>=4
时会出现运行失败的问题。
一个可能的解决办法是,使用更新版本的 coverage.py
来运行 py.test
,但不使用 pytest-cov
插件。
首先,安装 coverage >= 4
,并卸载 pytest-cov
插件:
pip install --pre --upgrade coverage
pip uninstall pytest-cov
接着,在 .coveragerc
文件中添加以下设置:
[run]
concurrency = gevent
然后用以下命令运行:
coverage run -m py.test
(而不是常规的 py.test
运行方式)