from unittest.mock import AsyncMock, MagicMock import pytest @pytest.fixture def reader_double(): """Factory of OPC reader doubles holding subscriptions for the given slots. Like the real ServerReader, `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