pytest-cov :
coverage.py 是 Python 推荐使用的覆盖率统计工具,pytest-cov 是 pytest 的插件,它可以让你在 pytest 中使用 cpverage.py;
使用 pytest-cov:
- 下载 pytest-cov :pip install pytest-cov;
- 进入项目路径使用 --cov 参数:pytest --cov=src;因为大多数项目的源码都是放在 src 目录下,所以指定 src 目录单独计算此目录的覆盖率并生成报告;
生成 HTML 统计报告:
- 命令:pytest --cov-src --cov-report=html
pytest-cov实战
本文详细介绍如何使用pytest-cov插件进行代码覆盖率统计。通过pip安装pytest-cov后,在项目路径中使用pytest --cov参数,可以指定src目录进行覆盖率计算。最后,通过pytest --cov-report=html生成HTML格式的统计报告。
1597

被折叠的 条评论
为什么被折叠?



