def test_RETRreadError(self):
        """
        Any errors during reading a file inside a RETR should be returned to
        the client.
        """
        # Make a failing file reading.
        class FailingFileReader(ftp._FileReader):
            def send(self, consumer):
                return defer.fail(ftp.IsADirectoryError("blah"))

        def failingRETR(a, b):
            return defer.succeed(FailingFileReader(None))

        # Monkey patch the shell so it returns a file reader that will
        # fail.
        self.patch(ftp.FTPAnonymousShell, 'openForReading', failingRETR)

        def check_response(failure):
            self.flushLoggedErrors()
            failure.trap(ftp.CommandFailed)
            self.assertEqual(
                failure.value.args[0][0],
                "125 Data connection already open, starting transfer")
            self.assertEqual(
                failure.value.args[0][1],
                "550 blah: is a directory")

        proto = _BufferingProtocol()
        d = self.client.retrieveFile('failing_file', proto)
        d.addErrback(check_response)
        return d

        Any errors during reading a file inside a RETR should be returned to
        the client.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_ftp.py