腾讯云
开发者社区
文档
建议反馈
控制台
登录/注册
首页
学习
活动
专区
圈层
工具
MCP广场
文章/答案/技术大牛
搜索
搜索
关闭
发布
文章
问答
(9999+)
视频
沙龙
1
回答
使用
FastAPI
TestClient
测试
返回
422
状态
代码
、
我尝试
使用
来自
FastAPI
的
TestClient
(基本上就是Scarlett
TestClient
)
测试
端点。 响应码总是
422
不可处理的实体。这是我当前的
代码
: from typing import Dict, Optional from pydantic import BaseModel这是我的
测试
: from
fastapi
.
testc
浏览 52
提问于2020-09-12
得票数 6
1
回答
测试
FastAPI
TestClient
请求
返回
422
、
、
我正在试着
测试
我的
代码
,但是我不知道我做错了什么。我将
FastAPI
与pydantic的基础模型结合
使用
。cats.append(new_cat)
使用
API创建cat时不会出现错误。# Testsfrom app.main import app 'breed': '", js
浏览 20
提问于2021-05-18
得票数 0
回答已采纳
2
回答
使用
FastAPI
+ pytest
测试
上载文本文件的端点时出错
、
、
upload_file.filename return file_uploader(filename, file_content)from typing import Generator from app.main import app yield
浏览 11
提问于2022-08-17
得票数 1
回答已采纳
1
回答
带有
FastAPI
的Pytest :断言错误(Response
422
)
、
、
、
、
我想用以下
代码
测试
FastAPI
: import pytestfrom main import applicationsclient =
TestClient
(app) "view, status_code", ("predict+ where
422</
浏览 87
提问于2021-01-07
得票数 0
1
回答
Python - mock函数和断言异常
、
、
、
、
我用
FastAPI
构建了一个与DynamoDB交互的应用程序接口。在我的
测试
驱动开发之旅的开始,我对模拟什么感到疑惑。这是get方法,main.py: router =
FastAPI
() def get_data(request: Request, device_idtest_main.py启动的
测试
文件中: from
fastapi
.
testclient
import
TestClient
浏览 22
提问于2021-08-28
得票数 1
回答已采纳
1
回答
如何用
FastAPI
(电机)实现
FastAPI
测试
、
、
、
、
我想为我的
FastAPI
端点编写
测试
from
fastapi
import
FastAPI
async def get_todo_by_title(title: str,current_user: User = Depends(get
浏览 5
提问于2022-04-26
得票数 3
2
回答
如何在
FastAPI
Pytest中断言预期的HTTPExceptions?
、
、
E
fastapi
.exceptions.HTTPException: (404, '404 test!') 为了在
测试
中正确预测HTTPExceptions,我遗漏了什么?
浏览 5
提问于2021-03-28
得票数 1
2
回答
用
FastApi
测试
上传多个文件
、
、
我正在试着将一个文件上传到
FastApi
,但是我一直收到
422
个验证错误。文件上载在OpenApi接口中工作,但下面的
测试
不起作用。@router.post("/files") return someprocessing(files)response = client.post(
浏览 26
提问于2022-09-05
得票数 0
回答已采纳
2
回答
FastAPI
:如何通过重写“`Depends()”中的函数来
测试
API
、
、
、
我是非常,非常新的
FastAPI
测试
,所以任何正确的方向指导将不胜感激。return { 'state': some_function_output我想
测试
一下这个对于我的
测试
,我现在拥有的是这样的东西:from typing import Union from
fastapi
import
浏览 9
提问于2022-05-25
得票数 0
回答已采纳
1
回答
FastAPI
路由在Swagger中工作,但在单元
测试
中
返回
HTTP
422
、
、
from
fastapi
import
FastAPI
def myroute(a: str, b: str) -> str:当我运行服务器并
使用
Swagger与其交互时,它可以正常工作。我有下面的单元
测试
。from
fastapi
.
testclient
import
浏览 11
提问于2022-08-24
得票数 0
回答已采纳
1
回答
FastAPI
后Pydantic方法单元
测试
重定向status_code 307而不是200
、
、
、
、
我有一个
测试
用例,在这里我
使用
托管在POST Uvicorn上的pytest来
测试
一个
FastAPI
服务。但是,响应会得到
状态
代码
307的响应。但这种情况不会发生在实际的webservice上,而是通过浏览器或curl进行
测试
。这里发生了什么事?from
fastapi
.
testclient
import
TestClient
import json client
浏览 7
提问于2022-09-27
得票数 0
回答已采纳
1
回答
如何用pytest在httpError中
测试
fastAPI
?
、
、
我正在尝试用
FastAPI
制作一些api服务器。在我的项目中有一个名为/hello的端点,它提供:现在我想知道:我如何提高和
测试
HTTPException的目的?requests.exceptions.HTTPError as e: raise HTTPException(status
浏览 10
提问于2022-07-10
得票数 0
1
回答
FastAPI
测试
客户端可以被外部调用吗?
、
、
、
我正在为
FastAPI
应用程序编写
测试
。我第一次需要做负载
测试
(用蝗虫)。但也引起了一些问题。我想:也许我可以
使用
FastAPI
测试
客户端,但我发现,我无法理解
测试
客户端是如何工作的。因为,显然,我不能从外面打电话给
测试
客户。有人能解释一下为什么,我可以让
TestClient
用于其他电话吗? 将基url设置为local
浏览 5
提问于2022-04-22
得票数 0
回答已采纳
1
回答
FastAPI
依赖覆盖失败
、
、
、
、
我正在
使用
MongoMock
测试
我的
FastAPI
应用程序,但是我可以“覆盖
FastAPI
的依赖性”。create_test_data将
使用
MongoMock的客户端插入一些假
测试
数据,并
返回
task_id请求所需的
测试
数据。from mongomock import MongoClientfrom pytest
浏览 11
提问于2022-04-18
得票数 0
2
回答
FastAPI
-向
TestClient
添加路由前缀
、
、
我有一个
FastAPI
应用程序,它的路径前缀为/api/v1。有没有一种方法可以避免根据前缀更改所有
测试
函数中的所有路由?这看起来很麻烦,因为有很多
测试
用例,也因为我不想在我的
测试
用例中
使用
硬编码的路由前缀依赖。import <em
浏览 11
提问于2021-09-13
得票数 6
回答已采纳
1
回答
如何更改
FastAPI
的
TestClient
中的客户端主机名?
、
、
我
使用
client.host从Request对象获取IP地址,并将其发送到另一个函数,在该函数中,我
使用
Pydantic的IPvAnyAddress来验证IP地址。这是我的
代码
:from pydantic import IPvAnyAddress def example_function(ip_address: IPvAnyAdd
浏览 21
提问于2022-09-09
得票数 1
1
回答
FastAPI
模拟路径函数不起作用
、
、
、
、
我有一个简单的应用程序,我正在尝试用pytest为它创建
测试
。from unittest import mock from starlette.
testclient
import
TestClient
from app.main impor
浏览 5
提问于2020-03-26
得票数 6
1
回答
如何在
FastAPI
中发布具有单个body参数的JSON?
、
我有一个名为main.py的文件,在该文件中,我只
使用
一个输入参数(整数)放置一个POST调用。简化
代码
如下:async def do_something(process_id: int): return {"process_id": process_id}
浏览 5
提问于2022-01-19
得票数 2
回答已采纳
1
回答
如何
测试
使用
镜像的
FastAPI
api端点?
、
、
、
、
我正在
使用
pytest
测试
一个
FastAPI
端点,该端点输入一个二进制格式的图像,如下所示async def analyse(file: bytes = File:from requests_toolbelt.multipart.encoder import MultipartEncoderpython -m pytest运行<
浏览 1
提问于2020-03-21
得票数 12
回答已采纳
2
回答
在
测试
过程中模拟环境变量
、
、
、
、
我有一个非常简单的
fastapi
应用程序,我想
测试
它,dummy_api.py的
代码
如下:from
fastapi
import
FastAPI
当我想
测试
这个文件时,我
使用
以下文件:import dummy_api def test_dummy_ap
浏览 5
提问于2021-02-16
得票数 0
回答已采纳
点击加载更多
热门
标签
更多标签
云服务器
ICP备案
云直播
即时通信 IM
实时音视频
活动推荐
运营活动
广告
关闭
领券