def test_loginError(self):
        """
        Unexpected exceptions from the login handler are caught
        """
        def _fake_loginhandler(*args, **kwargs):
            return defer.fail(AssertionError('test exception'))

        self.serverProtocol.portal.login = _fake_loginhandler
        d = self.client.queueStringCommand('USER foo')
        self.assertCommandFailed(
            'PASS bar',
            ['550 Requested action not taken: internal server error'],
            chainDeferred=d)

        @d.addCallback
        def checkLogs(result):
            logs = self.flushLoggedErrors()
            self.assertEqual(1, len(logs))
            self.assertIsInstance(logs[0].value, AssertionError)

        return d

        Unexpected exceptions from the login handler are caught
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_ftp.py