@@ -537,6 +537,41 @@ def test_add_method_parent_classes(parser):
537537 assert added_args == ["m.p2" , "m.a1" , "m.a2" , "m.a3" ]
538538
539539
540+ class Model :
541+ pass
542+
543+
544+ class TrainerLike :
545+ def foo (self , model : Model , x : int , y : float = 1.0 ):
546+ """Sample extra function.
547+
548+ Args:
549+ model: A model
550+ x: The x
551+ y: The y
552+ """
553+
554+
555+ @skip_if_docstring_parser_unavailable
556+ def test_add_method_required_argument_in_parse_args_help (parser ):
557+ parser .add_method_arguments (TrainerLike , "foo" , skip = {"model" })
558+
559+ help_str = get_parse_args_stdout (parser , ["--help" ])
560+ assert "The x (required, type: int)" in help_str
561+ assert "The y (type: float, default: 1.0)" in help_str
562+
563+
564+ @skip_if_docstring_parser_unavailable
565+ def test_add_method_required_argument_in_subcommand_parse_args_help (parser , subparser ):
566+ subparser .description = "Sample extra function:"
567+ subparser .add_method_arguments (TrainerLike , "foo" , skip = {"model" })
568+ parser .add_subcommands ().add_subcommand ("foo" , subparser )
569+
570+ help_str = get_parse_args_stdout (parser , ["foo" , "--help" ])
571+ assert "The x (required, type: int)" in help_str
572+ assert "The y (type: float, default: 1.0)" in help_str
573+
574+
540575# add_function_arguments tests
541576
542577
0 commit comments