admin管理员组文章数量:1355665
I need in tests GetBalancesRateThrottle.__call__
return None because of redis:
from fastapi import FastAPI, Depends
from redis.asyncio import Redis
from starlette.requests import Request
app = FastAPI()
class PartnerRateThrottle:
scope = None
rate = None
cache_format = 'throttle_%(scope)s_%(ident)s'
def __init__(self):
pass
async def __call__(self, request: Request):
redis = Redis(host=settings.redis_host, port=settings.redis_port)
# for simplicity it should return None
return None
class GetBalancesRateThrottle(PartnerRateThrottle):
scope = "balances"
rate = "rate"
@app.get(
"/balances",
dependencies=[
Depends(GetBalancesRateThrottle()),
],
)
async def get_balances(product_id: int):
# logic
But the test does not work:
def test_balances(mocker: MockerFixture):
mock = AsyncMock(return_value)
mocker.patch("path.to.GetBalancesRateThrottle.__call__", side_effect=mock)
How to make GetBalancesRateThrottle.__call__
return None?
本文标签: fastapiHow to mock async GetBalancesRateThrottlecall with PytestStack Overflow
版权声明:本文标题:fastapi - How to mock async GetBalancesRateThrottle.__call__ with Pytest? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743938329a2565096.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论