Skip to content

Bug: Adding a subscriber to a TestRabbitBroker persists between test runs #1036

Description

@HelgeKrueger

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

CoreIssues related to core FastStream functionality and affects to all brokersbugSomething isn't working

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions