在 Python 的覆盖范围内排除进口

Exclude imports from coverage in Python

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

coverage run -m pytest -v tests/

有没有办法排除 运行 导入包的测试范围?

感谢您的帮助。

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

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

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