Skip to content

Commit 5b99c3c

Browse files
committed
Resolve merge conflict and add repr test
1 parent cb82c40 commit 5b99c3c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

testing/test_argparsing_repr_fix.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Test case for issue #13817: AttributeError with invalid flag in pytest_addoption."""
2-
32
from __future__ import annotations
43

54
from _pytest.config.argparsing import ArgumentError
5+
from _pytest.config.argparsing import NOT_SET
66
from _pytest.config.argparsing import Parser
77
import pytest
88

@@ -63,3 +63,17 @@ def test_repr_with_dest_set(self) -> None:
6363
# Should contain the dest
6464
assert "dest: 'valid_dest'" in repr_str
6565
assert "NOT_SET" not in repr_str
66+
67+
def test_repr_without_dest(self) -> None:
68+
"""Test that __repr__ works when dest is not set due to error."""
69+
from _pytest.config.argparsing import Argument
70+
71+
# Create an Argument that will fail during initialization
72+
# This triggers the code path where dest is not set
73+
try:
74+
Argument("invalid") # No dashes, will fail
75+
except ArgumentError as exc:
76+
# The repr was called during error creation
77+
# Verify it contains NOT_SET representation
78+
assert "dest:" in str(exc)
79+
assert "NOT_SET" in str(exc) or "<notset>" in str(exc)

0 commit comments

Comments
 (0)