-
-
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
Open
thartline35
wants to merge
17
commits into
pytest-dev:main
Choose a base branch
from
thartline35:fix-issue-13817
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+82
−1
Open
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
88b144f
Fix AttributeError in Argument.__repr__ when dest is not set
thartline35 26f72b0
Add changelog and update AUTHORS
thartline35 d3bd04a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 163866c
Add return type annotations for mypy
thartline35 87f5942
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5d09ee7
Trigger CI checks
thartline35 a4f4696
Fix docstring to one line for ruff
thartline35 52d83ac
Add test for repr with dest set to improve coverage
thartline35 f0eeb1c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9d69b3d
Use NOT_SET constant instead of string literal
thartline35 bce848b
Merge branch 'fix-issue-13817' of https://github.com/thartline35/pyte…
thartline35 10f9167
Merge branch 'main' into fix-issue-13817
thartline35 8c43772
Update test to check for NOT_SET constant
thartline35 f341a1a
Merge branch 'fix-issue-13817' of https://github.com/thartline35/pyte…
thartline35 cb82c40
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5b99c3c
Resolve merge conflict and add repr test
thartline35 1435534
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixed ``AttributeError`` in ``Argument.__repr__`` when ``dest`` attribute is not set, which occurred when displaying error messages for invalid option names. The error now shows a helpful message instead of masking the original validation error. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| """ | ||
| Test case for issue #13817: AttributeError with invalid flag in pytest_addoption | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from _pytest.config.argparsing import ArgumentError | ||
| from _pytest.config.argparsing import Parser | ||
| import pytest | ||
|
|
||
|
|
||
| # Suppress warning about using private pytest API (we're testing pytest itself) | ||
| @pytest.mark.filterwarnings("ignore::pytest.PytestDeprecationWarning") | ||
| class TestArgumentReprFix: | ||
| """Test that Argument.__repr__ handles missing dest attribute.""" | ||
|
|
||
| def test_invalid_option_without_dashes(self) -> None: | ||
| """Test that invalid option names produce helpful error messages.""" | ||
| parser = Parser() | ||
|
|
||
| with pytest.raises(ArgumentError) as exc_info: | ||
| parser.addoption("shuffle") # Missing required -- prefix | ||
|
|
||
| error_message = str(exc_info.value) | ||
| assert "invalid long option string" in error_message | ||
| assert "shuffle" in error_message | ||
| assert "must start with --" in error_message | ||
|
|
||
| # Ensure no AttributeError is mentioned | ||
| assert "AttributeError" not in error_message | ||
| assert "has no attribute 'dest'" not in error_message | ||
|
|
||
| def test_invalid_short_option(self) -> None: | ||
| """Test that invalid short option names produce helpful error messages.""" | ||
| parser = Parser() | ||
|
|
||
| with pytest.raises(ArgumentError) as exc_info: | ||
| parser.addoption("-ab") # 3 chars, treated as invalid long option | ||
|
|
||
| error_message = str(exc_info.value) | ||
| # -ab is treated as invalid long option (3+ chars) | ||
| assert ( | ||
| "invalid long option string" in error_message | ||
| or "invalid short option string" in error_message | ||
| ) | ||
|
|
||
| def test_valid_option_works(self) -> None: | ||
| """Test that valid options still work correctly.""" | ||
| parser = Parser() | ||
| parser.addoption("--shuffle", action="store_true", help="Shuffle tests") | ||
|
|
||
| options = parser._anonymous.options | ||
| assert len(options) > 0 | ||
| assert "--shuffle" in options[0].names() |
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.
Uh oh!
There was an error while loading. Please reload this page.