def test_producesOnly10Times(self):
        """
        When the L{NonStreamingProducer} has resumeProducing called 10 times,
        it writes the counter each time and then fails.
        """
        consumer = TestConsumer()
        producer = NonStreamingProducer(consumer)
        consumer.registerProducer(producer, False)

        self.assertIs(consumer.producer, producer)
        self.assertIs(producer.consumer, consumer)
        self.assertFalse(consumer.producerStreaming)

        for _ in range(10):
            producer.resumeProducing()

        # We should have unregistered the producer and printed the 10 results.
        expectedWrites = [
            b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9'
        ]
        self.assertIsNone(consumer.producer)
        self.assertIsNone(consumer.producerStreaming)
        self.assertIsNone(producer.consumer)
        self.assertEqual(consumer.writes, expectedWrites)

        # Another attempt to produce fails.
        self.assertRaises(RuntimeError, producer.resumeProducing)

        When the L{NonStreamingProducer} has resumeProducing called 10 times,
        it writes the counter each time and then fails.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/internet/test/test_testing.py