Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
HelgeKrueger opened this issue Dec 11, 2023 · 3 comments
Assignees
Labels
bug Something isn't working Core Issues related to core FastStream functionality and affects to all brokers
Milestone

Comments

@HelgeKrueger
Copy link

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
@HelgeKrueger HelgeKrueger added the bug Something isn't working label Dec 11, 2023
@Lancetnik
Copy link
Member

Thank you for the Issue, I'll take a look tomorrow

@Lancetnik Lancetnik self-assigned this Dec 11, 2023
@Lancetnik Lancetnik moved this to In Progress in FastStream Dec 11, 2023
@Lancetnik
Copy link
Member

Well, TestClient patches the original broker indeed. And it doesn't make it in a clearest way. Seems like I have to refactor all test class logic and implementation and it can't be a fast fix, sorry.

@Lancetnik Lancetnik moved this from In Progress to Backlog in FastStream Dec 12, 2023
@HelgeKrueger
Copy link
Author

The behavior of this test case has changed. I can no longer add new subscribers after TestRabbitBroker has been called, instead I need to add them before creating the TestRabbitBroker.

However: This is an annoying issue, not actually a critical one.

@Lancetnik Lancetnik added this to the 0.6.0 milestone Mar 26, 2024
@Lancetnik Lancetnik added the Core Issues related to core FastStream functionality and affects to all brokers label May 16, 2024
@Lancetnik Lancetnik mentioned this issue Jun 9, 2024
63 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Core Issues related to core FastStream functionality and affects to all brokers
Projects
Status: Backlog
Development

No branches or pull requests

2 participants