-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix issue #13817: Fixed AttributeError in Argument.__repr__ when dest attribute is not set.
#13824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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.