FastStream¶
-
Back to Testing Overview
Return to the Testing overview page with all topics.
The harness does not import FastStream. TestKafkaBroker delivers the message. The event-mediator path reads invocations. The inbox-only subscriber reads inbox, and the command handler stays out of invocations.
See FastStream.
from faststream.kafka import TestKafkaBroker
async with TestKafkaBroker(broker) as test_broker:
async with test_harness.around(event_mediator, inbox=inbox) as harness:
await test_broker.publish({"order_id": "1"}, "order_events")
harness.invocations.assert_entered(AuditHandler)
A subscriber that only accepts the message into the inbox:
await test_broker.publish({"order_id": "1"}, "order_events")
assert harness.inbox.pending_count == 1
harness.invocations.assert_not_entered(CreateOrderHandler)
Library example: examples/testing/faststream_subscriber.py.