Fix issue #13817: Fixed AttributeError in Argument.__repr__ when dest attribute is not set.#13824
Open
thartline35 wants to merge 17 commits intopytest-dev:mainfrom
Open
Fix issue #13817: Fixed AttributeError in Argument.__repr__ when dest attribute is not set.#13824thartline35 wants to merge 17 commits intopytest-dev:mainfrom
AttributeError in Argument.__repr__ when dest attribute is not set.#13824thartline35 wants to merge 17 commits intopytest-dev:mainfrom
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
RonnyPfannschmidt
requested changes
Oct 18, 2025
Member
RonnyPfannschmidt
left a comment
There was a problem hiding this comment.
good start, thanks
please use the NOT_SET constant we have for that
… into fix-issue-13817
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
RonnyPfannschmidt
approved these changes
Oct 21, 2025
The-Compiler
requested changes
Oct 21, 2025
Member
The-Compiler
left a comment
There was a problem hiding this comment.
I think the tests will need another round of review here. Will follow up with a more detailed review tomorrow, travelling without laptop right now.
My main concerns are:
- They should be wherever existing tests are instead of a new file
- The good case tests are most likely redundant as we have existing tests
- Duplication can probably be reduced a lot via parametrization
- not quite clear why suppressing the deprecation warning and accessing private API is needed, might be fine though, will need to check once back on laptop
Member
RonnyPfannschmidt
left a comment
There was a problem hiding this comment.
We should not let self escape via exceptions in init
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.
Description
Fixes #13817
When an invalid option name is provided to
pytest_addoption()(e.g., missing the--prefix), pytest correctly detects the error but then fails while trying to display the error message. This results in anAttributeErrorthat obscures the original, helpful validation error.Root Cause
The
Argument.__repr__()method unconditionally accessesself.dest, which hasn't been set yet when initialization is interrupted by a validation error in_set_opt_strings().The Fix
Added a defensive
hasattr()check fordestin__repr__, following the same pattern already used for thetypeanddefaultattributes.Before
After
Changes
src/_pytest/config/argparsing.py: Addedhasattr()check fordestattributetesting/test_argparsing_repr_fix.pyAll tests pass locally.