Skip to content

Offer a way to handle conflicting options #12915

Open
@DieTapete

Description

@DieTapete

What's the problem this feature will solve?

When a user installs multiple plugins it is often the case that there are conflicting options. Currently there is no way to handle those conflicts but to uninstall one of the conflicting plugins. Also when adding custom options the user is forced to rename the option.

Describe the solution you'd like

There should be a way to either define a resolution for a conflict or to remove one of the conflicting options.

For example in the following case I remove a conflicting option from the playwright plugin before I add my own:

def pytest_addoption(parser):
    pw_options = parser.getgroup("playwright", "Playwright")
    # either rename the options
    pw_options.renameoption('--device', '--machine')
    # or remove it
    pw_options.removeoption('--device')
    parser.addoption(
        "--device",
        action="store",
        choices=devices
    )

Alternatively there could be a function handling conflicts, a crude approach would look like this

def resolve_options(option1, option2):
    if option1.group is None:
        return option1
    return option2

def pytest_addoption(parser):
    parser.conflict_handler = resolve_options

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: configrelated to config handling, argument parsing and config filetype: proposalproposal for a new feature, often to gather opinions or design the API around the new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions