Skip to content

Commit 2fbd4c4

Browse files
committed
[CI] Added message if test is running on another shard
1 parent 02d57bb commit 2fbd4c4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

conftest.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@
5858
}
5959

6060

61-
def should_run(nodeid: str, num_shards: int, shard_index: int) -> bool:
61+
def find_shard_index(nodeid: str, num_shards: int) -> int:
6262
"""
63-
Return true if this test should run on this shard
63+
Return the index of the shard that should run this test
6464
"""
6565
for prefix, target_shard_idx in FIXED_ALLOCATION_PREFIXES.items():
6666
if nodeid.startswith(prefix):
6767
if target_shard_idx >= num_shards:
6868
raise RuntimeError(
6969
f"Cannot collect sharded tests, {nodeid} has hardcoded shard index {target_shard_idx} among only {num_shards} shards"
7070
)
71-
return target_shard_idx == shard_index
71+
return target_shard_idx
7272

7373
if nodeid in HARDCODED_ALLOCATIONS:
7474
hash = HARDCODED_ALLOCATIONS[nodeid]
@@ -89,5 +89,10 @@ def pytest_collection_modifyitems(config, items):
8989

9090
print(f"Marking tests for shard {shard_index} of {num_shards}")
9191
for item in items:
92-
if not should_run(item.nodeid, num_shards=num_shards, shard_index=shard_index):
93-
item.add_marker(pytest.mark.skip())
92+
item_shard_index = find_shard_index(item.nodeid, num_shards=num_shards)
93+
item.add_marker(
94+
pytest.mark.skipif(
95+
item_shard_index != shard_index,
96+
reason=f"Test running on shard {item_shard_index} of {num_shards}",
97+
)
98+
)

0 commit comments

Comments
 (0)