faststream 测试简单说明

faststream 包含了TestBroker可以方便的进行测试,比如与pytest 集成

参考使用

  • app_test.py
import pytest
from faststream.redis import TestRedisBroker,RedisBroker
broker = RedisBroker("redis://localhost:6379",validate=False)
@pytest.mark.asyncio
async def test_correct():
    async with TestRedisBroker(broker,with_real=True) as br:
        await br.publish({
            "name": "John",
            "age": 1,
        }, "test")

说明

对于测试还是比较重要的,我们可以确保功能的稳定性

参考资料

https://faststream.airt.ai/latest/faststream/#testing-the-service

posted on 2024-09-16 00:02  荣锋亮  阅读(12)  评论(0编辑  收藏  举报

导航