This is an automated email from the ASF dual-hosted git repository.
areusch pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 3fbd9b66b7 [CI] Added message if test is running on another shard
(#11331)
3fbd9b66b7 is described below
commit 3fbd9b66b745eb59021c265a9708b6ac08f700d0
Author: Eric Lunderberg <[email protected]>
AuthorDate: Wed May 18 14:19:43 2022 -0500
[CI] Added message if test is running on another shard (#11331)
---
conftest.py | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/conftest.py b/conftest.py
index 9768b6cc52..3c04f0680a 100644
--- a/conftest.py
+++ b/conftest.py
@@ -58,9 +58,9 @@ FIXED_ALLOCATION_PREFIXES = {
}
-def should_run(nodeid: str, num_shards: int, shard_index: int) -> bool:
+def find_shard_index(nodeid: str, num_shards: int) -> int:
"""
- Return true if this test should run on this shard
+ Return the index of the shard that should run this test
"""
for prefix, target_shard_idx in FIXED_ALLOCATION_PREFIXES.items():
if nodeid.startswith(prefix):
@@ -68,7 +68,7 @@ def should_run(nodeid: str, num_shards: int, shard_index:
int) -> bool:
raise RuntimeError(
f"Cannot collect sharded tests, {nodeid} has hardcoded
shard index {target_shard_idx} among only {num_shards} shards"
)
- return target_shard_idx == shard_index
+ return target_shard_idx
if nodeid in HARDCODED_ALLOCATIONS:
hash = HARDCODED_ALLOCATIONS[nodeid]
@@ -76,7 +76,7 @@ def should_run(nodeid: str, num_shards: int, shard_index:
int) -> bool:
hash = hashlib.md5(nodeid.encode())
hash = int(hash.hexdigest(), 16)
- return hash % num_shards == shard_index
+ return hash % num_shards
def pytest_collection_modifyitems(config, items):
@@ -89,5 +89,10 @@ def pytest_collection_modifyitems(config, items):
print(f"Marking tests for shard {shard_index} of {num_shards}")
for item in items:
- if not should_run(item.nodeid, num_shards=num_shards,
shard_index=shard_index):
- item.add_marker(pytest.mark.skip())
+ item_shard_index = find_shard_index(item.nodeid, num_shards=num_shards)
+ item.add_marker(
+ pytest.mark.skipif(
+ item_shard_index != shard_index,
+ reason=f"Test running on shard {item_shard_index} of
{num_shards}",
+ )
+ )