从 Python 覆盖范围中排除导入

问题描述

目前,在使用 coverage 测试我的代码时,我的库覆盖率为 32%,由于 coverage,测量例如numpyscipy 和其他导入的 Python 库。 我使用的命令是

coverage run -m pytest -v tests/

有没有办法排除导入包的运行测试覆盖率?

感谢您的帮助。

解决方法

通过 --source 中的 coverage 选项找到解决方案:

coverage run --source ./ -m pytest -v tests/

其中 ./ 是我想包含在报告中的当前目录,也是唯一的目录。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...