Skip to content

Commit

Permalink
Add empty sentinel item in WorkerInteractor queue
Browse files Browse the repository at this point in the history
When pytest_runtest_protocol is called with item==nextitem multiple times, with a test that accepts some fixtures -> the second call forward raises an error.

This is causes in WorkerInteractor when the same test appears twice in a row in its items queue.

To deal with this, we define an "empty" item that shall allow us to call pytest_runtest_protocol with nextitem=None, effectively solving this problem so long sequential executions of the same items are delimited by these empty items in the queue.
  • Loading branch information
yuvalino authored May 31, 2024
1 parent 7cc6515 commit 7968383
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/xdist/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def worker_title(title: str) -> None:
class Marker(enum.Enum):
SHUTDOWN = 0
QUEUE_REPLACED = 1
EMPTY = 2


class WorkerInteractor:
Expand Down Expand Up @@ -144,6 +145,8 @@ def handle_command(
self.torun.put(Marker.SHUTDOWN)
elif name == "steal":
self.steal(kwargs["indices"])
elif name == "empty":
self.torun.put(Marker.EMPTY)

def steal(self, indices: Sequence[int]) -> None:
indices_set = set(indices)
Expand Down Expand Up @@ -171,6 +174,8 @@ def pytest_runtestloop(self, session: pytest.Session) -> bool:
self.channel.setcallback(self.handle_command, endmarker=Marker.SHUTDOWN)
self.nextitem_index = self._get_next_item_index()
while self.nextitem_index is not Marker.SHUTDOWN:
while self.nextitem_index is Marker.EMPTY:
self.nextitem_index = self._get_next_item_index()
self.run_one_test()
if session.shouldfail or session.shouldstop:
break
Expand All @@ -183,7 +188,7 @@ def run_one_test(self) -> None:

items = self.session.items
item = items[self.item_index]
if self.nextitem_index is Marker.SHUTDOWN:
if self.nextitem_index in [Marker.SHUTDOWN, Marker.EMPTY]:
nextitem = None
else:
assert self.nextitem_index is not None
Expand Down

0 comments on commit 7968383

Please sign in to comment.