Skip to content

Test CLI help uses the command's context class - #430

Open
smprather wants to merge 1 commit into
posit-dev:mainfrom
smprather:test/click-custom-context-help
Open

smprather wants to merge 1 commit into
posit-dev:mainfrom
smprather:test/click-custom-context-help

Conversation

@smprather

Copy link
Copy Markdown

Summary

Adds a regression test for _get_click_help_text() building the help context from cmd.context_class rather than a plain click.Context.

This is the behavior that makes help rendering work for commands whose context builds a custom formatter — Typer's vendored Click and rich-click's RichContext, for example. The existing context_class implementation is correct; this test pins it.

The test defines a click.Command with a custom context/formatter that requires a config attribute, then asserts _get_click_help_text() returns the usage text. Against the old click.Context(cmd, ...) construction the test fails with:

AttributeError: 'HelpFormatter' object has no attribute 'config'

With cmd.context_class(...) it passes.

Tests

  • PYTHONPATH=$PWD pytest tests/test_cli_help_context.py -q → 1 passed
  • Verified RED by temporarily restoring click.Context(cmd, ...); the test failed with the expected AttributeError.

No production code changes.

Checklist

  • I understand and agree to the Code of Conduct.
  • I have followed PEP 8 as best as possible.
  • I have added pytest unit tests for the behavior.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant