pytest-dev / pytest-dev/pytest

Offer a way to handle conflicting options

Open
#12,915 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: config type: proposal
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the pytest_addoption entry point and the parser methods shown in the issue. Compare the requested rename/remove behavior with the alternative conflict-resolution hook. Done means the project has a decided, documented way to resolve conflicting plugin options, including the examples described.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.