from unittest.mock import AsyncMock, MagicMock from pytest import fixture @fixture def reader_double(): """Factory of OPC reader doubles holding subscriptions for the given slots. Like the real readers (ServerReader, OpcManager), `subscriptions` is keyed by slot and `unsubscribe` drops the slot from it. """ def make(*slots): reader = MagicMock() reader.subscriptions = {slot: MagicMock() for slot in slots} reader.unsubscribe = AsyncMock(side_effect=lambda slot: reader.subscriptions.pop(slot)) return reader return make