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