def test_cleanup_is_called_on_running_producer(self): producer = Producer(MagicMock(), async_send=True) producer.stopped = False with patch.object(producer, 'stop') as mocked_stop: producer._cleanup_func(producer) self.assertEqual(mocked_stop.call_count, 1)
def test_cleanup_is_not_called_on_stopped_producer(self): producer = Producer(MagicMock(), async=True) producer.stopped = True with patch.object(producer, "stop") as mocked_stop: producer._cleanup_func(producer) self.assertEqual(mocked_stop.call_count, 0)