def runTest(self, mock_gp):
        """Test 'st2 login' ability to detect unhandled exceptions"""

        expected_username = self.TOKEN["user"]
        args = ["--config", self.CONFIG_FILE, "login", expected_username]

        mock_gp.getpass = mock.MagicMock(side_effect=Exception)

        self.shell.run(args)
        retcode = self.shell.run(args)

        self.assertIn(
            "Failed to log in as %s" % expected_username, self.stdout.getvalue()
        )
        self.assertNotIn("Logged in as", self.stdout.getvalue())
        self.assertEqual(retcode, 1)
Test 'st2 login' ability to detect unhandled exceptions
st2client/tests/unit/test_auth.py