python - 为什么不使用 starlettes TestClient 使用 pytest-cov 获得 100% 的 FastAPI 覆盖率
问题描述
我根本不明白 pytest-cov 的输出
我的测试模块如下
from starlette.testclient import TestClient
def test_ping(test_app: TestClient):
response = test_app.get("/ping")
assert response.status_code == 200
assert response.json() == {"environment": "dev", "ping": "pong!", "testing": True}
即我不理解 1 部分和 1 缺失。完整的 CLI 报告:
❯ docker-compose exec web coverage report -m
Name Stmts Miss Branch BrPart Cover Missing
--------------------------------------------------------------------
app/__init__.py 0 0 0 0 100%
app/api/__init__.py 0 0 0 0 100%
app/api/crud.py 14 0 2 0 100%
app/api/ping.py 7 1 2 1 78% 267, 10->9
app/api/summaries.py 20 0 8 5 82% 12->11, 12->19, 19->18, 19->24, 24->23
app/config.py 12 0 2 1 93% 16->15
app/db_init.py 8 1 0 0 88% 268
app/main.py 19 2 4 3 78% 270-274, 25->24, 25->31, 31->30
app/models/__init__.py 0 0 0 0 100%
app/models/pydantic.py 5 0 0 0 100%
app/models/tortoise.py 9 1 0 0 89% 11
db_generate_schema.py 13 13 2 0 0% 1-274
--------------------------------------------------------------------
TOTAL 107 18 20 10 76%
我首先想了解丢失267, 10->9
的内容-该文件中的行数甚至不超过 15 行。这可能也可以解释剩下的问题。
解决方案
推荐阅读
- php - 在数据库中使用调整大小的列或拆分表
- c# - 异常:System.NullReferenceException
- apache-spark - 在pyspark中计算窗口上列的百分位数
- javascript - 如何以对象数组的形式传递数据?
- azure-active-directory - 是否可以使用在单个 Azure 租户中注册的 APP 在多个域中创建用户。使用 Graph Rest API
- spring-boot - Spring Boot Preflight 请求未通过访问控制检查
- angular - 如何将我的 Angular 应用程序转换为 Http 模式
- python - 比较两列中的字符串以生成新列
- wso2 - WSO2 脚本调解器将整数显示为浮点数
- java - 不在事务中时在 JOOQ ExecuteListener 中执行查询