TestMQTTBroker
faststream.mqtt.TestMQTTBroker #
TestMQTTBroker(
broker: MQTTBroker,
/,
*,
with_real: bool = False,
connect_only: bool | None = None,
)
TestMQTTBroker(
*brokers: MQTTBroker,
with_real: bool = False,
connect_only: bool | None = None,
)
TestMQTTBroker(
*brokers: MQTTBroker,
with_real: bool = False,
connect_only: bool | None = None,
)
Bases: TestBroker[MQTTBroker, EnterType]
In-memory test double for MQTTBroker.
Routes published messages to matching subscribers without a real MQTT connection, using MQTT wildcard rules for topic matching. Messages are encoded in the same wire format as the configured broker version (V311 envelope or V5 PublishProperties).
Usage::
async with TestMQTTBroker(broker) as br:
await br.publish("hello", "sensors/temp")
handler.mock.assert_called_once_with("hello")
Source code in faststream/mqtt/testing.py
create_publisher_fake_subscriber #
create_publisher_fake_subscriber(
broker: MQTTBroker, publisher: MQTTPublisher
) -> tuple[MQTTBaseSubscriber, bool]