pytest-dev / pytest-dev/pytest
`AttributeError` with invalid flag added in `pytest_addoption`
Open
Nobody has claimed this yet.
type: bug
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
With Python 3.13.7 and pytest-8.4.2, doing this in a conftest.py:
def pytest_addoption(parser):
parser.addoption("shuffle") # without --
results in:
Traceback (most recent call last):
...
File ".../conftest.py", line 2, in pytest_addoption
parser.addoption("shuffle")
~~~~~~~~~~~~~~~~^^^^^^^^^^^
File "/usr/lib/python3.13/site-packages/_pytest/config/argparsing.py", line 102, in addoption
self._anonymous.addoption(*opts, **attrs)
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/site-packages/_pytest/config/argparsing.py", line 406, in addoption
option = Argument(*opts, **attrs)
File "/usr/lib/python3.13/site-packages/_pytest/config/argparsing.py", line 300, in __init__
self._set_opt_strings(names)
~~~~~~~~~~~~~~~~~~~~~^^^^^^^
File "/usr/lib/python3.13/site-packages/_pytest/config/argparsing.py", line 349, in _set_opt_strings
raise ArgumentError(
~~~~~~~~~~~~~^
f"invalid long option string {opt!r}: "
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
"must start with --, followed by non-dash",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
self,
^^^^^
)
^
File "/usr/lib/python3.13/site-packages/_pytest/config/argparsing.py", line 268, in __init__
self.option_id = str(option)
~~~^^^^^^^^
File "/usr/lib/python3.13/site-packages/_pytest/config/argparsing.py", line 362, in __repr__
args += ["dest: " + repr(self.dest)]
^^^^^^^^^
AttributeError: 'Argument' object has no attribute 'dest'
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The traceback points to _pytest/config/argparsing.py, especially Argument._set_opt_strings and repr; start there and inspect how invalid option names are rendered. Add a regression test for parser.addoption("shuffle") and verify it reports the invalid option error without an AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100