Skip to content

Commit 4e5f8e7

Browse files
committed
tests: fix conftest sort to preserve definition order within files
The previous sort key used item.name as tie-breaker, which sorted tests alphabetically within each file. This broke test_tablets.py where test_tablets_invalidation_decommission_non_cc_node (a destructive test that decommissions a node) was moved before test_tablets_invalidation_drop_ks, causing the latter to fail. Use the original collection index as tie-breaker instead, preserving the definition order inside each file while still grouping modules by cluster topology across files.
1 parent 80267dd commit 4e5f8e7

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

tests/integration/standard/conftest.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@
4040

4141

4242
def pytest_collection_modifyitems(items):
43-
"""Sort tests so modules with the same cluster topology are adjacent."""
43+
"""Sort tests so modules with the same cluster topology are adjacent.
44+
45+
Uses the original collection index as tie-breaker so that the
46+
definition order inside each file is preserved (important for tests
47+
that depend on running order, e.g. destructive tablet tests).
48+
"""
49+
orig_order = {id(item): idx for idx, item in enumerate(items)}
50+
4451
def _sort_key(item):
4552
module_name = item.module.__name__.rsplit(".", 1)[-1]
46-
return (_MODULE_CLUSTER_ORDER.get(module_name, 99), item.fspath, item.name)
53+
return (_MODULE_CLUSTER_ORDER.get(module_name, 99), item.fspath, orig_order[id(item)])
4754

4855
items[:] = sorted(items, key=_sort_key)
4956

0 commit comments

Comments
 (0)