diff --git a/certbot/cli.py b/certbot/cli.py index 45ee78103..1023d9aca 100644 --- a/certbot/cli.py +++ b/certbot/cli.py @@ -1303,7 +1303,7 @@ class _PrefChallAction(argparse.Action): try: challs = parse_preferred_challenges(pref_challs.split(",")) except errors.Error as error: - raise argparse.ArgumentTypeError(str(error)) + raise argparse.ArgumentError(self, str(error)) namespace.pref_challs.extend(challs) diff --git a/certbot/tests/cli_test.py b/certbot/tests/cli_test.py index d29f7c1b6..f18da240a 100644 --- a/certbot/tests/cli_test.py +++ b/certbot/tests/cli_test.py @@ -211,7 +211,10 @@ class ParseTest(unittest.TestCase): self.assertEqual(namespace.pref_challs, expected) short_args = ['--preferred-challenges', 'jumping-over-the-moon'] - self.assertRaises(argparse.ArgumentTypeError, self.parse, short_args) + # argparse.ArgumentError makes argparse print more information + # to stderr and call sys.exit() + with mock.patch('sys.stderr'): + self.assertRaises(SystemExit, self.parse, short_args) def test_server_flag(self): namespace = self.parse('--server example.com'.split())