Describe the bug
If I create a TestRabbitBroker in a fixture, and then add a subscriber. This subscriber is still available in the next test. As the fixture is function scoped, so on every call this means that the subscriber is added to the real broker.
One can work around this by creating the broker in a factory method.
How to reproduce
Install pytest + faststream[rabbit] save source as 'test_bug.pythen runpytest`
import pytest
import pytest_asyncio
from faststream.rabbit import RabbitBroker, TestRabbitBroker
broker = RabbitBroker("bug")
@pytest_asyncio.fixture
async def test_broker():
async with TestRabbitBroker(broker) as br:
yield br
@pytest.mark.asyncio
async def test_one(test_broker):
@test_broker.subscriber("queue")
async def sub():
return "foo"
result = await broker.publish("", queue="queue", rpc=True)
assert result == "foo"
@pytest.mark.asyncio
async def test_two(test_broker):
result = await broker.publish("", queue="queue", rpc=True)
assert result == "foo"...
Environment
Include the output of the faststream -v command to display your current project and system environment.
Running FastStream 0.3.3 with CPython 3.11.6 on Linux
Describe the bug
If I create a TestRabbitBroker in a fixture, and then add a subscriber. This subscriber is still available in the next test. As the fixture is function scoped, so on every call this means that the subscriber is added to the real broker.
One can work around this by creating the broker in a factory method.
How to reproduce
Install
pytest + faststream[rabbit]save source as 'test_bug.pythen runpytest`Environment
Include the output of the
faststream -vcommand to display your current project and system environment.