def test_transferError(self):
        """
        If there is an error while producing the message body to the
        connection, the C{sendError} callback is invoked.
        """
        client = MySMTPClient(
            ('alice@example.com', ['bob@example.com'], BytesIO(b"foo")))
        transport = StringTransport()
        client.makeConnection(transport)
        client.dataReceived(
            b'220 Ok\r\n' # Greeting
            b'250 Ok\r\n' # EHLO response
            b'250 Ok\r\n' # MAIL FROM response
            b'250 Ok\r\n' # RCPT TO response
            b'354 Ok\r\n' # DATA response
            )

        # Sanity check - a pull producer should be registered now.
        self.assertNotIdentical(transport.producer, None)
        self.assertFalse(transport.streaming)

        # Now stop the producer prematurely, meaning the message was not sent.
        transport.producer.stopProducing()

        # The sendError hook should have been invoked as a result.
        self.assertIsInstance(client._error, Exception)

        If there is an error while producing the message body to the
        connection, the C{sendError} callback is invoked.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/mail/test/test_smtp.py