Skip to content

Raise ValueError for non-option names in addoption() - #14880

Open
arronKler wants to merge 1 commit into
pytest-dev:mainfrom
arronKler:fix/13817-addoption-invalid-flag
Open

Raise ValueError for non-option names in addoption()#14880
arronKler wants to merge 1 commit into
pytest-dev:mainfrom
arronKler:fix/13817-addoption-invalid-flag

Conversation

@arronKler

Copy link
Copy Markdown

parser.addoption("shuffle") (missing --) is treated by argparse as a required positional argument. The original report was a secondary AttributeError while formatting that failure; after the argparse rewrite the same call still fails later with a dest-conflict or "arguments are required" error.

Reject names that do not start with - or -- at registration time, and suggest the --name form when the missing prefix is the likely typo.

Fixes #13817

parser.addoption("shuffle") was accepted as a positional argument
and later failed with a confusing required-argument or dest-conflict
error. Reject names that do not start with '-' or '--'.

Fixes pytest-dev#13817
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Aug 14, 2026
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.

AttributeError with invalid flag added in pytest_addoption

1 participant