pytest-dev / pytest-dev/pytest-xdist

--dist=loadgroup mix tests of different groups between same workers.

Open
#1,241 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.9k
Forks
287
Avg merge
9h 30m
Merged PRs (30d)
2

Description

goal:
To segregate tests to nodes by marker such as test of a different marker are grouped in the separate nodes.

each test file include tests cases with one of 4 different xdist_group:

@pytest.mark.xdist_group("setup_one")
def test_smonethig()
    ...


@pytest.mark.xdist_group("setup_two")
def test_smonethig__setup_two()
    ...

@pytest.mark.xdist_group("setup_three")
def test_smonethig__setup_three()
    ...

@pytest.mark.xdist_group("setup_four")

when run : -n 4 --dist=loadgroup -vv
i can see same groups were run on gw0, gw1, gw2, and gw3.

Q1: shouldnt they run each group on separate node?

currently i have added markers manually.

Q2: ps dynamically adding xdist_group marker on pytest_collection_modifyitems():

def pytest_collection_modifyitems(config: Config, items: list[nodes.Item]):
    ...
    test_case.add_marker(pytest.mark.xdist_group(name=test_case_app_setup)) 
   #or
   test_case.nodeid = f"test_case@test_case_app_setup"

doesnt work. (in verbose mode nodeid finish on test name with @group_name when marked manually but still mixed between nodes, dynamically marking doesnt work).
is it becasue xdist override this method?
or to add marker dynamically should implement it in other hook?

I can create dict(app_setup: list(nodesId) and assigned it to config attribute.
But still cant cant figure how to pass it to xdist "Scheduler"..
Many thanks in advance

Env:

platform linux -- Python 3.13.7, 
pytest-8.4.1, 
pluggy-1.6.0
configfile: pyproject.toml
plugins: respx-0.22.0, 
cov-6.2.1, 
mock-3.14.1, 
xdist-3.8.0, 
requests-mock-1.12.1, 
split-0.10.0, 
anyio-4.10.0

Contributor guide

No contributing guide indexed for this repository

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

Reproduce the behavior with -n 4 --dist=loadgroup -vv and the four xdist_group markers described. Start at pytest_collection_modifyitems() and the xdist Scheduler entry points to determine how collection and group assignment are transferred to workers. Done means the intended group-to-worker behavior and the supported approach for dynamically assigned groups are clarified or corrected.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.