Flask测试覆盖率 #

一、安装 #

bash
pip install pytest-cov

二、运行覆盖率测试 #

bash
pytest --cov=app
pytest --cov=app --cov-report=html

三、配置文件 #

.coveragerc:

ini
[run]
source = app
omit = app/tests/*

[report]
exclude_lines =
    pragma: no cover
    def __repr__

四、下一步 #

接下来让我们学习 生产环境配置,了解生产环境部署!

最后更新:2026-03-28