Skip to content

Commit 96175cb

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent badd083 commit 96175cb

File tree

4 files changed

+36
-34
lines changed

4 files changed

+36
-34
lines changed

Diff for: src/xdist/scheduler/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
from xdist.scheduler.loadgroup import LoadGroupScheduling as LoadGroupScheduling
55
from xdist.scheduler.loadscope import LoadScopeScheduling as LoadScopeScheduling
66
from xdist.scheduler.protocol import Scheduling as Scheduling
7-
from xdist.scheduler.singlecollect import SingleCollectScheduling as SingleCollectScheduling
7+
from xdist.scheduler.singlecollect import (
8+
SingleCollectScheduling as SingleCollectScheduling,
9+
)
810
from xdist.scheduler.worksteal import WorkStealingScheduling as WorkStealingScheduling

Diff for: src/xdist/scheduler/singlecollect.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
class SingleCollectScheduling:
1414
"""Implement scheduling with a single test collection phase.
15-
15+
1616
This differs from LoadScheduling by:
1717
1. Only collecting tests on the first node
1818
2. Skipping collection on other nodes
1919
3. Not checking for collection equality
20-
20+
2121
This can significantly improve startup time by avoiding redundant collection
2222
and collection verification across multiple worker processes.
2323
"""
@@ -72,7 +72,7 @@ def add_node(self, node: WorkerController) -> None:
7272
"""Add a new node to the scheduler."""
7373
assert node not in self.node2pending
7474
self.node2pending[node] = []
75-
75+
7676
# Remember the first node as our collector
7777
if self.first_node is None:
7878
self.first_node = node
@@ -145,11 +145,11 @@ def check_schedule(self, node: WorkerController, duration: float = 0) -> None:
145145
def remove_node(self, node: WorkerController) -> str | None:
146146
"""Remove a node from the scheduler."""
147147
pending = self.node2pending.pop(node)
148-
148+
149149
# If this is the first node (collector), reset it
150150
if node == self.first_node:
151151
self.first_node = None
152-
152+
153153
if not pending:
154154
return None
155155

@@ -208,4 +208,4 @@ def _send_tests(self, node: WorkerController, num: int) -> None:
208208
if tests_per_node:
209209
del self.pending[:num]
210210
self.node2pending[node].extend(tests_per_node)
211-
node.send_runtest_some(tests_per_node)
211+
node.send_runtest_some(tests_per_node)

Diff for: testing/acceptance_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_ok():
2525
result.stdout.fnmatch_lines(["*1 passed*"])
2626
# Make sure the tests are correctly distributed
2727
result.stdout.fnmatch_lines(["*scheduling tests via SingleCollectScheduling*"])
28-
28+
2929
def test_singlecollect_many_tests(self, pytester: pytest.Pytester) -> None:
3030
"""Test that the singlecollect mode correctly distributes many tests."""
3131
# Create test file with multiple tests
@@ -42,7 +42,7 @@ def test_ok(x):
4242
result.stdout.fnmatch_lines(["*passed*"])
4343
# Make sure the tests are correctly distributed
4444
result.stdout.fnmatch_lines(["*scheduling tests via SingleCollectScheduling*"])
45-
45+
4646
def test_singlecollect_failure(self, pytester: pytest.Pytester) -> None:
4747
"""Test that failures are correctly reported with singlecollect mode."""
4848
p1 = pytester.makepyfile(
@@ -54,7 +54,7 @@ def test_fail():
5454
result = pytester.runpytest(p1, "-n2", "--dist=singlecollect", "-v")
5555
assert result.ret == 1
5656
result.stdout.fnmatch_lines(["*1 failed*"])
57-
57+
5858
def test_singlecollect_handles_fixtures(self, pytester: pytest.Pytester) -> None:
5959
"""Test that fixtures work correctly with singlecollect mode."""
6060
pytester.makepyfile(

Diff for: testing/test_dsession.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -482,22 +482,22 @@ def test_add_node_and_collection(self, pytester: pytest.Pytester) -> None:
482482
config = pytester.parseconfig("--tx=2*popen")
483483
sched = SingleCollectScheduling(config)
484484
node1, node2 = MockNode(), MockNode()
485-
485+
486486
# First node should be set as collector
487487
sched.add_node(node1)
488488
assert sched.first_node == node1
489-
489+
490490
# Second node should not become the collector
491491
sched.add_node(node2)
492492
assert sched.first_node == node1
493-
493+
494494
# Collection from first node should be used
495495
collection = ["a.py::test_1", "a.py::test_2", "a.py::test_3"]
496496
sched.add_node_collection(node1, collection)
497497
assert sched.collection == collection
498498
assert sched.collection_done
499499
assert sched.collection_is_completed
500-
500+
501501
# Collection from second node should be ignored
502502
different_collection = ["a.py::test_1", "a.py::test_4"]
503503
sched.add_node_collection(node2, different_collection)
@@ -510,21 +510,21 @@ def test_schedule_tests(self, pytester: pytest.Pytester) -> None:
510510
node1, node2 = MockNode(), MockNode()
511511
sched.add_node(node1)
512512
sched.add_node(node2)
513-
513+
514514
collection = ["a.py::test_1", "a.py::test_2", "a.py::test_3", "a.py::test_4"]
515515
sched.add_node_collection(node1, collection)
516-
516+
517517
# Should use collection from node1 and distribute tests
518518
sched.schedule()
519-
519+
520520
# Check that tests were distributed across both nodes
521521
assert len(node1.sent) > 0
522522
assert len(node2.sent) > 0
523-
523+
524524
# Tests should be distributed completely
525525
all_tests = node1.sent + node2.sent
526526
assert sorted(all_tests) == list(range(len(collection)))
527-
527+
528528
# The pending list should be empty after distribution
529529
assert not sched.pending
530530

@@ -534,37 +534,37 @@ def test_handle_node_failure(self, pytester: pytest.Pytester) -> None:
534534
node1, node2 = MockNode(), MockNode()
535535
sched.add_node(node1)
536536
sched.add_node(node2)
537-
537+
538538
collection = ["a.py::test_1", "a.py::test_2", "a.py::test_3", "a.py::test_4"]
539539
sched.add_node_collection(node1, collection)
540540
sched.schedule()
541-
541+
542542
# Simulate node1 completing a test
543543
test_idx = node1.sent[0]
544544
sched.mark_test_complete(node1, test_idx)
545-
545+
546546
# Now remove node2 (simulating failure)
547547
crashitem = sched.remove_node(node2)
548-
548+
549549
# Tests assigned to node2 should go back to pending
550550
assert len(sched.pending) > 0
551-
551+
552552
# Add a new node
553553
node3 = MockNode()
554554
sched.add_node(node3)
555-
555+
556556
# Since collection is already completed, schedule should assign pending tests to node3
557557
sched.schedule()
558558
assert len(node3.sent) > 0
559-
559+
560560
# Complete all tests
561561
for idx in node1.sent:
562562
if idx != test_idx: # Skip the one we already completed
563563
sched.mark_test_complete(node1, idx)
564-
564+
565565
for idx in node3.sent:
566566
sched.mark_test_complete(node3, idx)
567-
567+
568568
# All tests should be completed
569569
assert sched.tests_finished
570570

@@ -573,25 +573,25 @@ def test_first_node_failure(self, pytester: pytest.Pytester) -> None:
573573
config = pytester.parseconfig("--tx=2*popen")
574574
sched = SingleCollectScheduling(config)
575575
node1, node2 = MockNode(), MockNode()
576-
576+
577577
# First node should be collector
578578
sched.add_node(node1)
579579
assert sched.first_node == node1
580-
580+
581581
# Add second node
582582
sched.add_node(node2)
583-
583+
584584
# First node fails before collection
585585
sched.remove_node(node1)
586-
586+
587587
# Now second node should become the collector
588588
assert sched.first_node is None # first_node is reset after removal
589-
589+
590590
# Add a new node, it should become the collector
591591
node3 = MockNode()
592592
sched.add_node(node3)
593593
assert sched.first_node == node3
594-
594+
595595
# Complete collection with node3
596596
collection = ["a.py::test_1", "a.py::test_2"]
597597
sched.add_node_collection(node3, collection)

0 commit comments

Comments
 (0)