Skip to content

Reject implicit option destination conflicts#14661

Open
w-Jessamine wants to merge 3 commits into
pytest-dev:mainfrom
w-Jessamine:fix/implicit-option-dest-conflict
Open

Reject implicit option destination conflicts#14661
w-Jessamine wants to merge 3 commits into
pytest-dev:mainfrom
w-Jessamine:fix/implicit-option-dest-conflict

Conversation

@w-Jessamine

Copy link
Copy Markdown

Summary

Fixes #12824.

Custom options added with parser.addoption() can currently derive an implicit dest that collides with an existing pytest option. For example, --keyword derives dest="keyword", which silently overwrites the built-in -k option destination and causes the value to be interpreted as a keyword selection expression.

This change rejects implicit destination conflicts with a clear error, while still allowing intentional shared destinations when dest=... is passed explicitly. That preserves existing pytest patterns such as --capture/-s and --maxfail/-x.

Testing

  • python -m pytest testing/test_parseopt.py testing/test_config.py -q
  • python -m ruff check src/_pytest/config/argparsing.py testing/test_parseopt.py
  • python -m ruff format --check src/_pytest/config/argparsing.py testing/test_parseopt.py

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jun 29, 2026
for group in self.parser._groups:
for option in group.options:
if option.dest == dest:
raise ValueError(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit pick but I am thinking if we make the error message a bit more clear?

Maybe something like:

"option dest keyword already used by ['-k'] (this is the option that maps to dest keyword); pass dest='keyword' explicitly to share the destination"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, updated the error message to include the existing option and explicit dest guidance.

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.

Conflicting custom arguments does not raise obvious error

2 participants