Testing
See the requests a bus dispatches.
Traceable bus
A decorator for a Bus that records all requests that it handles. This is useful in testing and debugging a usage of the bus.
Usage
Wrap an existing bus in the traceable bus, and use it as normal.
bus = banshee.TraceableBus(
banshee.Builder()
.with_registry()
.build()
)
await bus.handle(GreetCommand(name="joe"))
print(bus.messages)
Reference
- class banshee.TraceableBus(inner)
Bases:
Bus
Traceable bus.
A
Bus
decorator that stores information about the processing of each message passed to the wrapped instance.- Parameters:
inner (Bus) – decorated instance
- property messages: Sequence[MessageInfo]
Messages.
- Returns:
sequence containing information about each message processed.
- reset()
Reset.
Clear everything in
messages
.- Return type:
None
- class banshee.MessageInfo(request, contexts, filename, function, lineno, timestamp, result_contexts=None)
Bases:
object
Message information.
Contains information about the handling of as specific message.
- Parameters:
- filename: str
filename where call originated
- function: str
function where call originated
- lineno: int
line in file where call originated
- request: object
request object
- timestamp: datetime
timestamp of call