Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loadgroup: Don't modify test nodeids any longer. #1119

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/xdist/dsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ def pytest_terminal_summary(self, terminalreporter: Any) -> None:
terminalreporter.write_sep("=", f"xdist: {self._summary_report}")

def worker_collectionfinish(
self, node: WorkerController, ids: Sequence[str]
self,
node: WorkerController,
ids: Sequence[str],
loadgroup_scopes: dict[str, str],
) -> None:
"""Worker has finished test collection.

Expand All @@ -290,6 +293,7 @@ def worker_collectionfinish(
assert self._session is not None
self._session.testscollected = len(ids)
assert self.sched is not None
self.sched.loadgroup_scopes = loadgroup_scopes
self.sched.add_node_collection(node, ids)
if self.terminal:
self.trdist.setstatus(
Expand Down
32 changes: 13 additions & 19 deletions src/xdist/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,30 +201,25 @@ def run_one_test(self) -> None:
"runtest_protocol_complete", item_index=self.item_index, duration=duration
)

def pytest_collection_modifyitems(
self,
config: pytest.Config,
items: list[pytest.Item],
) -> None:
# add the group name to nodeid as suffix if --dist=loadgroup
if config.getvalue("loadgroup"):
for item in items:
mark = item.get_closest_marker("xdist_group")
if not mark:
continue
gname = (
mark.args[0]
if len(mark.args) > 0
else mark.kwargs.get("name", "default")
)
item._nodeid = f"{item.nodeid}@{gname}"

@pytest.hookimpl
def pytest_collection_finish(self, session: pytest.Session) -> None:
# collect the scope for each node for --dist=loadgroup
loadgroup_scopes = {}
for item in session.items:
mark = item.get_closest_marker("xdist_group")
if not mark:
continue
gname = (
mark.args[0]
if len(mark.args) > 0
else mark.kwargs.get("name", "default")
)
loadgroup_scopes[item.nodeid] = gname
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An important Note here is that unfortunately duplicate node ids are only discouraged,not enforced

Which is the reason for using the node index instead of the node id when communicating using the scheduler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty bad. What's your opinion, does this need to be addressed, or can we live with duplicate node ids being scheduled on the same node, per xdist_group, even only one test had the annotation?

self.sendevent(
"collectionfinish",
topdir=str(self.config.rootpath),
ids=[item.nodeid for item in session.items],
loadgroup_scopes=loadgroup_scopes,
)

@pytest.hookimpl
Expand Down Expand Up @@ -356,7 +351,6 @@ def getinfodict() -> WorkerInfo:


def setup_config(config: pytest.Config, basetemp: str | None) -> None:
config.option.loadgroup = config.getvalue("dist") == "loadgroup"
config.option.looponfail = False
config.option.usepdb = False
config.option.dist = "no"
Expand Down
7 changes: 3 additions & 4 deletions src/xdist/scheduler/loadgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def _split_scope(self, nodeid: str) -> str:
gname
gname
"""
if nodeid.rfind("@") > nodeid.rfind("]"):
# check the index of ']' to avoid the case: parametrize mark value has '@'
return nodeid.split("@")[-1]
if nodeid in self.loadgroup_scopes:
return self.loadgroup_scopes[nodeid]
else:
return nodeid
return super()._split_scope(nodeid)
7 changes: 6 additions & 1 deletion src/xdist/workermanage.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,12 @@ def process_from_remote(
rep.item_index = item_index
self.notify_inproc(eventname, node=self, rep=rep)
elif eventname == "collectionfinish":
self.notify_inproc(eventname, node=self, ids=kwargs["ids"])
self.notify_inproc(
eventname,
node=self,
ids=kwargs["ids"],
loadgroup_scopes=kwargs["loadgroup_scopes"],
)
elif eventname == "runtest_protocol_complete":
self.notify_inproc(eventname, node=self, **kwargs)
elif eventname == "unscheduled":
Expand Down