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

标签 python code-coverage gevent pytest

py.test + gevent 如何得到准确的测试覆盖率报告?

我已经尝试过显而易见的事情,使用 py.testpytest-cov 插件,但它 generates inaccurate reports when gevent is in use .

最佳答案

gevent coverage issue最近在 coveragepy 中得到修复。

但是,pytest-cov 无法运行 coverage>=4

一个可能的修复方法是在不使用 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 运行)

关于python - 使用 py.test + gevent 确定测试覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22890779/

相关文章:

python - 使用Python OpenCV的ANN实现以实现手写识别

java - 计划上手代码覆盖工具

python - viewflow.io : Is there a way to have 'subflows' ?

java - Cobertura Maven 插件在 Windows 上失败并显示 "The command line is too long"

c - Lcov:无法收集分支覆盖率统计

python - 如何使用 `gevent.pywsgi.WSGIServer` 和 `WebSocketHandler` 启用 Flask 应用程序的日志记录?

python - 热重载 gevent WSGIServer

socket.io - gevent-socketio + Flask + Gunicorn

python - 在python中用一个列表生成两组组合

python - 如何在scrapy中获取div中<p>标签的数量?