Skip to content

Substitute %(default)s in ini option help text (#9244)#14556

Open
alimkozak wants to merge 1 commit into
pytest-dev:mainfrom
alimkozak:addini-default-help
Open

Substitute %(default)s in ini option help text (#9244)#14556
alimkozak wants to merge 1 commit into
pytest-dev:mainfrom
alimkozak:addini-default-help

Conversation

@alimkozak
Copy link
Copy Markdown

Fixes #9244.

Command-line options added with addoption already expand %(default)s in their help to the default value (argparse does this). Ini options added with addini are rendered by pytest itself in showhelp(), so %(default)s showed up literally in pytest --help.

This PR replaces %(default)s with the option's default value when rendering the ini help. I used a targeted str.replace rather than %-formatting, so help texts that contain a literal % are not affected.

Changes

  • helpconfig.py: substitute %(default)s with the ini option's default in showhelp().
  • config/argparsing.py: document the help parameter of addini.
  • testing/test_helpconfig.py: add a regression test.
  • changelog entry (9244.improvement.rst).

Command-line options added with `addoption` already expand `%(default)s`
in their help text to the option's default value, because argparse does it.
Ini options added with `addini` are rendered by pytest itself in
`showhelp()`, so the token was shown literally in `pytest --help`.

Replace `%(default)s` with the option's default when rendering ini help.
A targeted string replace (instead of `%`-formatting) is used so help
texts containing a literal `%` keep working.

Closes pytest-dev#9244.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jun 4, 2026
Copy link
Copy Markdown
Member

@The-Compiler The-Compiler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an exact replacement for %(default)s is quite the hack. According to the Python documentation, other replacements work (type, prog, etc. etc.), so why should one of them work but not others? Also it seems unexpected that this uses the Python percent formatting syntax but then behaves differently for raw % signs.

I can see the importance of keeping backwards compat however, so maybe this needs something like a interpolate_help=True flag or somesuch (which is False by default)?

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

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow interpolating values into getini help

2 participants