pytest-dev / pytest-dev/pytest-xdist
Modifying xdist options - pytest_hookimpl(tryfirst=True) doesn't work
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 287
- Avg merge
- 9h 30m
- Merged PRs (30d)
- 2
Description
I am trying to add a new option to xdist's --dist flag. In my plugin.py file:
@pytest.hookimpl
def pytest_addoption(parser: pytest.Parser) -> None:
# Modify the existing xdist 'dist' option to add our new scheduling mode
group = parser.getgroup("xdist", "distributed and subprocess testing")
distopt = next(filter(lambda opt: opt.dest == "dist", group.options), None)
distopt._attrs["choices"].append("perdevice")
The issue here is that I require xdist to have already added options before I can modify them. This is confusing me a bit because according to Pytest's documentation, plugin hooks are run on a LIFO basis - I would think since this new plugin is registered last, it would execute first.
In any case, the documentation also says you can influence the calls order using pytest.hookimpl(tryfirst=True). I haven't found this to work at all. Looking at the source code of xdist, the option for tryfirst isn't enabled, so I don't understand why this isn't working. Even adding trylast doesn't work.
Any ideas why this isn't working? I am using pytest-xdist 3.8.0 if that is relevant.
Contributor guide
No contributing guide indexed for this repository
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
Start with the pytest_addoption example in the issue and read pytest-xdist/src/xdist/plugin.py around the linked line 63. Trace how the xdist and external plugin hooks are registered and ordered, including the effects of tryfirst and trylast. Done means explaining why the ordering options do not produce the expected result and identifying the relevant supported approach or documentation change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- distributed-systems, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100