@@ -419,6 +419,56 @@ def test_iter_params_for_processing(
419419 )
420420
421421
422+ @pytest .mark .parametrize (
423+ ("help_option_names" , "params" , "expected" ),
424+ [
425+ # A single default name is returned unchanged.
426+ (["--help" ], [], ["--help" ]),
427+ # Declaration order is preserved verbatim, whatever it is.
428+ (["-h" , "--help" ], [], ["-h" , "--help" ]),
429+ (["--help" , "-h" ], [], ["--help" , "-h" ]),
430+ (["--help" , "-h" , "-?" ], [], ["--help" , "-h" , "-?" ]),
431+ (["-?" , "--help" , "-h" ], [], ["-?" , "--help" , "-h" ]),
432+ # Duplicate names collapse to their first occurrence, keeping order.
433+ (["--help" , "--help" ], [], ["--help" ]),
434+ (["-h" , "--help" , "-h" ], [], ["-h" , "--help" ]),
435+ # A name already claimed by another parameter's option is dropped.
436+ (["-h" , "--help" ], [["--help" ]], ["-h" ]),
437+ (["-h" , "--help" ], [["-h" , "--verbose" ]], ["--help" ]),
438+ # Both options of a feature-switch flag are removed too.
439+ (["--shout" , "--help" ], [["--shout/--no-shout" ]], ["--help" ]),
440+ (["--no-shout" , "--help" ], [["--shout/--no-shout" ]], ["--help" ]),
441+ # Filtering every name out yields an empty list.
442+ (["-h" , "--help" ], [["-h" ], ["--help" ]], []),
443+ # Deduplication and conflict removal combine, order still preserved.
444+ (["-h" , "--help" , "-h" , "--assist" ], [["--assist" ]], ["-h" , "--help" ]),
445+ ],
446+ ids = [
447+ "default" ,
448+ "order-short-long" ,
449+ "order-long-short" ,
450+ "order-three" ,
451+ "order-three-shuffled" ,
452+ "dedupe-adjacent" ,
453+ "dedupe-spread" ,
454+ "conflict-long" ,
455+ "conflict-short" ,
456+ "conflict-flag-on" ,
457+ "conflict-flag-off" ,
458+ "all-removed" ,
459+ "dedupe-and-conflict" ,
460+ ],
461+ )
462+ def test_get_help_option_names (help_option_names , params , expected ):
463+ """Check help option names are deduplicated but keep stable order.
464+
465+ https://github.com/pallets/click/pull/3728
466+ """
467+ cli = click .Command ("cli" , params = [click .Option (decls ) for decls in params ])
468+ ctx = click .Context (cli , help_option_names = help_option_names )
469+ assert cli .get_help_option_names (ctx ) == expected
470+
471+
422472def test_help_param_priority (runner ):
423473 """Cover the edge-case in which the eagerness of help option was not
424474 respected, because it was internally generated multiple times.
0 commit comments