【pytest】pytest-cov :统计代码测试覆盖率

pytest-cov :

coverage.py 是 Python 推荐使用的覆盖率统计工具,pytest-cov 是 pytest 的插件,它可以让你在 pytest 中使用 cpverage.py;

使用 pytest-cov: 

  1. 下载 pytest-cov :pip install pytest-cov;
  2. 进入项目路径使用 --cov 参数:pytest --cov=src;因为大多数项目的源码都是放在 src 目录下,所以指定 src 目录单独计算此目录的覆盖率并生成报告;

生成 HTML 统计报告:

  • 命令:pytest --cov-src --cov-report=html

你可能感兴趣的:(pytest,测试覆盖率,代码测试覆盖率,覆盖率报告)