上一页 1 2 3 4 5 6 ··· 205 下一页
摘要: 一,报错信息: ERROR [alembic.util.messaging] Target database is not up to date. FAILED: Target database is not up to date. 二,原因 手动同步状态:你手动修改了数据库结构,使其已经与最新的模 阅读全文
posted @ 2026-07-29 23:14 刘宏缔的架构森林 阅读(2) 评论(0) 推荐(0)
摘要: 一,手动保存库信息到requirements.txt 例如: $ pip freeze > requirements.txt 二,通过requirements.txt安装项目所需依赖 pip install -r requirements.txt 阅读全文
posted @ 2026-07-29 15:04 刘宏缔的架构森林 阅读(6) 评论(0) 推荐(0)
摘要: 一,说明: 1,测试异步函数时,你必须在函数前加上 await, 并且测试用例本身也要是 async def,同时需要打上 @pytest.mark.asyncio 标签 2,在 FastAPI 中,很多 service 层或 CRUD 函数都需要传入一个数据库 AsyncSession。 测试这类 阅读全文
posted @ 2026-07-28 23:44 刘宏缔的架构森林 阅读(5) 评论(0) 推荐(0)
摘要: 一,说明: 如果你的函数是纯同步的,按照标准 Python 测试编写即可,不需要任何特殊配置 二,代码: 待测试函数: # app/utils/functions.py def format_user_role(role_id: int) -> str: """根据角色ID返回角色名称""" rol 阅读全文
posted @ 2026-07-28 22:45 刘宏缔的架构森林 阅读(2) 评论(0) 推荐(0)
摘要: 一,代码: 因为接口是从header中获取用户token,所以测试时就是在 AsyncClient 发送请求时,通过 headers 参数直接传入 mock 的 Token; @pytest.mark.asyncio async def test_get_user_info_success(asyn 阅读全文
posted @ 2026-07-28 14:42 刘宏缔的架构森林 阅读(4) 评论(0) 推荐(0)
摘要: 一,安装用到的库 $ pip install pytest pytest-asyncio httpx sqlalchemy aiomysql 二,代码 结构: conftest.py # tests/conftest.py (API 专有) import asyncio import pytest 阅读全文
posted @ 2026-07-28 12:53 刘宏缔的架构森林 阅读(5) 评论(0) 推荐(0)
摘要: 一,报错信息 E RuntimeError: Task <Task pending name='Task-6' coro=<_wrap_asyncgen_fixture.<locals>._asyncgen_fixture_wrapper.<locals>.finalizer.<locals>.as 阅读全文
posted @ 2026-07-28 10:45 刘宏缔的架构森林 阅读(3) 评论(0) 推荐(0)
摘要: 一,报错信息: $ pytest ImportError while loading conftest '/data/python/fastapi/demo1/tests/conftest.py'. tests/conftest.py:6: in <module> from app.core.dat 阅读全文
posted @ 2026-07-27 22:39 刘宏缔的架构森林 阅读(6) 评论(0) 推荐(0)
摘要: 一,用到的方法 核心转换方法总结 Pydantic 模型 ➔ Python 字典:model.model_dump() Pydantic 模型 ➔ JSON 字符串:model.model_dump_json() JSON 字符串 ➔ Pydantic 模型:Model.model_validate 阅读全文
posted @ 2026-07-27 20:43 刘宏缔的架构森林 阅读(3) 评论(0) 推荐(0)
摘要: 要构建一个生产可用的 FastAPI 完善脚手架(Boilerplate),你需要从工程化、业务通用功能、运维监控三个维度进行系统化设计。 以下是核心建设任务清单: 📁 1. 基础架构与目录分层 规范的目录结构是脚手架的基础,建议采用异步(Async)架构和分层设计: 解耦分层:划分 schema 阅读全文
posted @ 2026-07-27 14:26 刘宏缔的架构森林 阅读(10) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 ··· 205 下一页