summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_argparse.py
diff options
context:
space:
mode:
authorHai Shi <shihai1992@gmail.com>2019-09-12 10:56:05 (GMT)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-09-12 10:56:05 (GMT)
commitf545638b5701652ffbe1774989533cdf5bc6631e (patch)
tree27c90f441b2aa84cf770ff3782550947b4ab36af /Lib/test/test_argparse.py
parent2d32bf1ef23c9e468b2e8afab3c24e7a2047ac36 (diff)
downloadcpython-f545638b5701652ffbe1774989533cdf5bc6631e.zip
cpython-f545638b5701652ffbe1774989533cdf5bc6631e.tar.gz
cpython-f545638b5701652ffbe1774989533cdf5bc6631e.tar.bz2
bpo-9938: Add optional keyword argument exit_on_error to argparse.ArgumentParser (GH-15362)
Co-Authored-by: Xuanji Li <xuanji@gmail.com> https://bugs.python.org/issue9938 Automerge-Triggered-By: @matrixise
Diffstat (limited to 'Lib/test/test_argparse.py')
-rw-r--r--Lib/test/test_argparse.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index 86ec6cc..464db29 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -5262,6 +5262,21 @@ class TestWrappingMetavar(TestCase):
'''))
+class TestExitOnError(TestCase):
+
+ def setUp(self):
+ self.parser = argparse.ArgumentParser(exit_on_error=False)
+ self.parser.add_argument('--integers', metavar='N', type=int)
+
+ def test_exit_on_error_with_good_args(self):
+ ns = self.parser.parse_args('--integers 4'.split())
+ self.assertEqual(ns, argparse.Namespace(integers=4))
+
+ def test_exit_on_error_with_bad_args(self):
+ with self.assertRaises(argparse.ArgumentError):
+ self.parser.parse_args('--integers a'.split())
+
+
def test_main():
support.run_unittest(__name__)
# Remove global references to avoid looking like we have refleaks.