MockEventPublisher

class safir.metrics.MockEventPublisher(application, event_class, logger)

Bases: NoopEventPublisher, Generic[P]

Event publisher that quietly does nothing and records all payloads.

This is meant to be used in unit tests to enable assertions on published payloads. It should NOT be used in any deployed application instances because memory usage will grow unbounded with each published event.

Parameters:

Attributes Summary

published

A list of published event payloads with some test helpers.

Methods Summary

publish(payload)

Publish an event payload.

Attributes Documentation

published

A list of published event payloads with some test helpers.

Methods Documentation

async publish(payload)

Publish an event payload.

Parameters:

payload (TypeVar(P, bound= EventPayload)) – Payload to publish.

Returns:

Full, enriched-with-metadata event model that was published. This will be an object of a class derived from both the type of the payload and EventMetadata, but it is typed as the latter since that is the newly-added information that may be of interest to the caller and therefore the most likely to be accessed.

Return type:

EventMetadata