def test_channel_subscribe(self):
    self.assertEqual(self.pubsub.subscribe('foo'), ['subscribe', 'foo', 1])
self.assertEqual(self.client.publish('foo', 'hello foo'), 1)
self.assertEqual(next(self.pubsub.listen()), {'type': 'message',
    'pattern': None, 'channel': 'foo', 'data': 'hello foo'})
self.assertEqual(self.pubsub.unsubscribe('foo'), ['unsubscribe', 'foo', 0])

def test_pattern_subscribe(self):
    self.assertEqual(self.pubsub.psubscribe('fo*'), ['psubscribe', 'fo*', 1])
self.assertEqual(self.client.publish('foo', 'hello foo'), 1)
self.assertEqual(next(self.pubsub.listen()), {'type': 'pmessage',
    'pattern': 'fo*', 'channel': 'foo', 'data': 'hello foo'})
self.assertEqual(self.pubsub.punsubscribe('fo*'), ['punsubscribe', 'fo*', 0])
Push messages to clients in Python