首页 / pallets/click 范例 / click-req-3896

click-req-3896

需求原文

背景

CliRunner.invoke() 会把多余的关键字参数传给命令的 Context,但 color 例外:invoke() 自己有一个 color 参数占了这个名字。于是测试里没法在同一次调用中,既设定终端支持情况、又设定Context 的 color。

这个问题 5 年前在 #2110 提过,当时被认为太小众;此后 Click 做了一系列颜色处理改进(#3505、#3653、#3739),颜色相关的测试多了很多,不再是小众需求。

需求

给 CliRunner.invoke() 加一个 context_settings 参数,让测试能把上下文相关的设置传给命令的 Context,从而解决 color 的名字冲突。

验收标准

来源

来源:examples/click-req-3896.md

相关文件 / 函数

文件关联命中符号
src/click/core.py种子Context.invoke (L877), Group.invoke (L2043), Command.invoke (L1423), Context.fail (L834)
src/click/testing.py种子CliRunner.invoke (L625), BytesIOCopy.write (L157), BytesIOCopy.flush (L153), _FDCapture.start (L124)
tests/test_testing.py种子test_args (L439), test_catch_exceptions (L211), test_env (L384), test_capture_fd_windows_error (L759), test_pdb_init_restored_after_invoke (L732)
tests/test_options.py种子test_dual_options_custom_type_sentinel_flag_value.main (L2447), test_default_dual_option_callback.main (L2015), test_custom_type_flag_value_dual_options (L2687), test_default_dual_option_callback (L1997), test_show_default_boolean_flag_name (L1611)
docs/testing.md种子—
tests/test_termui.py1 跳邻居test_choices_list_in_prompt (L257), test_progressbar_update (L318), test_prompt_required_with_required (L1339), test_progressbar_hidden_manual (L101), test_progressbar_strip_regression (L44)
tests/test_defaults.py1 跳邻居test_lookup_default_callable_in_default_map (L202), test_default_map_source (L253), test_flag_default_map (L110), test_nargs_plus_multiple (L63), test_basic_defaults (L22)
tests/test_basic.py1 跳邻居test_option_reusing_help_flag (L88), test_basic_functionality (L12), test_choice_argument_custom_type (L584), test_param_squatting_help_option_name (L71), test_boolean_switch (L303)
tests/test_commands.py种子test_custom_parser.OptParseCommand.invoke (L171), test_other_command_invoke.cli (L11), test_custom_parser (L144), test_deprecated_in_help_messages (L554), test_group_with_args (L129)
tests/test_custom_classes.py1 跳邻居test_context_invoke_type (L20), test_context_invoke_type.first (L40)

共 10 个文件,约 7350 tokens(预算内)。

调用链

flowchart LR
    src_click_core_py__Context_invoke --> src_click_core_py___make_sub_context
    src_click_core_py__Context_invoke --> src_click_core_py__augment_usage_errors
    src_click_core_py__Context_invoke --> src_click_core_py__callback
    src_click_core_py__Context_invoke --> src_click_core_py__get_default
    src_click_core_py__Context_invoke --> src_click_core_py__type_cast_value
    src_click_core_py__Group_invoke --> src_click_core_py___process_result
    src_click_core_py__Group_invoke --> src_click_core_py__fail
    src_click_core_py__Group_invoke --> src_click_core_py__invoke
    src_click_core_py__Group_invoke --> src_click_core_py__make_context
    src_click_core_py__Group_invoke --> src_click_core_py__resolve_command
    src_click_core_py__Command_invoke --> src_click_core_py___format_deprecated_suffix
    src_click_core_py__Command_invoke --> src_click_core_py__echo
    src_click_core_py__Command_invoke --> src_click_core_py__invoke
    src_click_core_py__Command_invoke --> src_click_core_py__style
    src_click_core_py__Context_fail --> src_click_core_py__UsageError
    src_click_testing_py__CliRunner_invoke --> src_click_testing_py__Result
    src_click_testing_py__CliRunner_invoke --> src_click_testing_py___FDCapture
    src_click_testing_py__CliRunner_invoke --> src_click_testing_py__flush
    src_click_testing_py__CliRunner_invoke --> src_click_testing_py__get_default_prog_name
    src_click_testing_py__CliRunner_invoke --> src_click_testing_py__getvalue

群消息佐证

验收