cosmicpython/code

Chapter 9: Unit Testing Event Handlers in Isolation - small bug

dayres2 opened this issue · 2 comments

Hi,

I found that to get the additional isolation test to work when testing BatchQuantityChanged I had to override collect_new_events in FakeUnitOfWorkWithFakeMessageBus not publish_events and then return an empty list.

Small issue but thought I would raise it. Nice book by the way.
Cheers,
Dan

hjwp commented

oo good catch! something like this?

class FakeUnitOfWorkWithFakeMessageBus(FakeUnitOfWork):
    def __init__(self):
        super().__init__()
        self.events_published = []  # type: List[events.Event]

    def collect_new_events(self):
        self.events_published += super().collect_new_events()
        return []

looks good. Thanks Harry