@inlineCallbacks
    def test_cancel(self):
        channel = self.channel
        #setup, declare a queue:
        yield channel.queue_declare(queue="test-queue-4", exclusive=True)
        yield channel.basic_consume(consumer_tag="my-consumer", queue="test-queue-4")
        channel.basic_publish(routing_key="test-queue-4", content=Content("One"))

        #cancel should stop messages being delivered
        yield channel.basic_cancel(consumer_tag="my-consumer")
        channel.basic_publish(routing_key="test-queue-4", content=Content("Two"))
        myqueue = yield self.client.queue("my-consumer")
        msg = yield myqueue.get(timeout=1)
        self.assertEqual("One", msg.content.body)
        try:
            msg = yield myqueue.get(timeout=1)
            self.fail("Got message after cancellation: " + msg)
        except Empty: None

        #cancellation of non-existent consumers should be handled without error
        yield channel.basic_cancel(consumer_tag="my-consumer")
        yield channel.basic_cancel(consumer_tag="this-never-existed")
Test compliance of the basic.cancel method
dataset/ETHPy150Open tweetdeck/txAMQP/src/txamqp/test/test_basic.py/BasicTests.test_cancel