Substitute %(default)s in ini option help text (#9244)#14556
Open
alimkozak wants to merge 1 commit into
Open
Conversation
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>
The-Compiler
requested changes
Jun 4, 2026
Member
The-Compiler
left a comment
There was a problem hiding this comment.
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)?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9244.
Command-line options added with
addoptionalready expand%(default)sin their help to the default value (argparse does this). Ini options added withaddiniare rendered by pytest itself inshowhelp(), so%(default)sshowed up literally inpytest --help.This PR replaces
%(default)swith the option's default value when rendering the ini help. I used a targetedstr.replacerather than%-formatting, so help texts that contain a literal%are not affected.Changes
helpconfig.py: substitute%(default)swith the ini option's default inshowhelp().config/argparsing.py: document thehelpparameter ofaddini.testing/test_helpconfig.py: add a regression test.9244.improvement.rst).