pytest-dev / pytest-dev/pytest-xdist
[loadgroup] How to make one group always run in gw0
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 287
- Avg merge
- 9h 30m
- Merged PRs (30d)
- 2
Description
I am using pytest-xdist for parallel test execution, and I have grouped my test classes into two groups using the @pytest.mark.xdist_group("group1") and @pytest.mark.xdist_group("group2") decorators.
I then use the -n 2 and --dist loadgroup options to distribute tests by their groups, which works as expected by ensuring tests from the same xdist_group are grouped together.
However, I am facing an issue where the distribution of test groups across workers is not deterministic. The following two scenarios are possible:
Scenario 1:
gw0 runs all tests decorated with @pytest.mark.xdist_group("group1"), and gw1 runs all tests decorated with @pytest.mark.xdist_group("group2").
Scenario 2:
gw0 runs all tests decorated with @pytest.mark.xdist_group("group2"), and gw1 runs all tests decorated with @pytest.mark.xdist_group("group1").
This randomness in the worker assignment is problematic for my use case.
I want to ensure that all tests marked with group1 are always assigned to gw0 and all tests marked with group2 are always assigned to gw1, with no random distribution or switching of the groups between workers.
Is there a recommended way to enforce this specific assignment of tests to workers with pytest-xdist?
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 by reviewing pytest-xdist's --dist loadgroup behavior and the @pytest.mark.xdist_group markers described in the issue. Determine whether the requested fixed group-to-worker assignment is supported, and define a reproducible way to verify that group1 always runs on gw0 and group2 on gw1.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100