Skip to content
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
Prev Previous commit
Next Next commit
[FIX] Fix mypy errors.
  • Loading branch information
zorhay committed Mar 3, 2025
commit 58083487578558b83f0337b8da301ba2f1a73f7e
14 changes: 7 additions & 7 deletions src/xdist/scheduler/singlecollect.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

class SingleCollectScheduling:
"""Implement scheduling with a single test collection phase.

This differs from LoadScheduling by:
1. Only collecting tests on the first node
2. Skipping collection on other nodes
3. Not checking for collection equality

This can significantly improve startup time by avoiding redundant collection
and collection verification across multiple worker processes.
"""
Expand Down Expand Up @@ -72,7 +72,7 @@ def add_node(self, node: WorkerController) -> None:
"""Add a new node to the scheduler."""
assert node not in self.node2pending
self.node2pending[node] = []

# Remember the first node as our collector
if self.first_node is None:
self.first_node = node
Expand All @@ -92,10 +92,10 @@ def add_node_collection(
self.log(f"Ignoring collection from node {node.gateway.id}")

def mark_test_complete(
self, node: WorkerController, item_index: int, duration: float = 0
self, node: WorkerController, item_index: int | str, duration: float = 0
) -> None:
"""Mark test item as completed by node."""
self.node2pending[node].remove(item_index)
self.node2pending[node].remove(int(item_index) if isinstance(item_index, str) else item_index)
self.check_schedule(node, duration=duration)

def mark_test_pending(self, item: str) -> None:
Expand Down Expand Up @@ -145,11 +145,11 @@ def check_schedule(self, node: WorkerController, duration: float = 0) -> None:
def remove_node(self, node: WorkerController) -> str | None:
"""Remove a node from the scheduler."""
pending = self.node2pending.pop(node)

# If this is the first node (collector), reset it
if node == self.first_node:
self.first_node = None

if not pending:
return None

Expand Down
3 changes: 1 addition & 2 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ def test_singlecollect_handles_fixtures(self, pytester: pytest.Pytester) -> None
pytester.makepyfile(
"""
import pytest

@pytest.fixture
def my_fixture():
return 42

def test_with_fixture(my_fixture):
assert my_fixture == 42
"""
Expand Down
3 changes: 2 additions & 1 deletion testing/test_dsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def test_handle_node_failure(self, pytester: pytest.Pytester) -> None:
sched.mark_test_complete(node1, test_idx)

# Now remove node2 (simulating failure)
crashitem = sched.remove_node(node2)
sched.remove_node(node2)

# Tests assigned to node2 should go back to pending
assert len(sched.pending) > 0
Expand Down Expand Up @@ -590,6 +590,7 @@ def test_first_node_failure(self, pytester: pytest.Pytester) -> None:
# Add a new node, it should become the collector
node3 = MockNode()
sched.add_node(node3)
# Verify the new node became the collector
assert sched.first_node == node3

# Complete collection with node3
Expand Down
Loading