python / cpython

The Python programming language
https://www.python.org
Other
63.01k stars 30.17k forks source link

missing unittests for overlapping dest when using subparsers #89794

Open 7a064fe6-c535-4d80-a11f-a04ed39056c5 opened 2 years ago

7a064fe6-c535-4d80-a11f-a04ed39056c5 commented 2 years ago
BPO 45631
Nosy @rhettinger, @ALSchwalm

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = None closed_at = None created_at = labels = [] title = 'missing unittests for overlapping dest when using subparsers' updated_at = user = 'https://bugs.python.org/paulj3' ``` bugs.python.org fields: ```python activity = actor = 'paul.j3' assignee = 'none' closed = False closed_date = None closer = None components = [] creation = creator = 'paul.j3' dependencies = [] files = [] hgrepos = [] issue_num = 45631 keywords = [] message_count = 1.0 messages = ['405110'] nosy_count = 3.0 nosy_names = ['rhettinger', 'paul.j3', 'ALSchwalm'] pr_nums = [] priority = 'normal' resolution = None stage = 'needs patch' status = 'open' superseder = None type = None url = 'https://bugs.python.org/issue45631' versions = [] ```

7a064fe6-c535-4d80-a11f-a04ed39056c5 commented 2 years ago

https://bugs.python.org/issue45235 argparse does not preserve namespace with subparser defaults

was passed and put into the latest release with rather obvious buggy behavior.

This means that the unittest file does not adequately test for overlapping 'dest' in the main and subparsers. It probably also does not test many (any?) cases of user provided namespace.

bpo-9351 added a test, but it only tested defaults set with

parser.set_defaults(foo=1)
xparser.set_defaults(foo=2)

not the more common practice of setting defaults in add_argument.

45235 adds one test, but again only for

xparser.set_defaults(foo=1)

It doesn't test for user inputs, as with

['X','--foo=3']

AbhigyanBose commented 2 years ago

I'd like to fill in the missing unit tests. I'm not sure if I'd be able to find/fill up everything, I'd like to start off with listing what are the scenarios that still need to be covered. I'm not very familiar with the module, so I'd really appreciate some guidance regarding what other unit tests might be missing.

As pointed by @paulj3 I checked and I didn't find any test cases with user provided Namespaces.

Missing test cases that need to be added:

  1. Check that user provided Namespace overrides default value.
  2. Check that user provided value overrides user provided Namespace.

I obtained the above two scenarios from the discussions in https://bugs.python.org/issue45235. Thanks.