Skip to content

AttributeError with invalid flag added in pytest_addoption #13817

@The-Compiler

Description

@The-Compiler

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions