Skip to content

Commit adaf5c8

Browse files
committed
Fix handling of parametrized tests
- adapt test to catch the bug - see #38
1 parent e199488 commit adaf5c8

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

pytest_order/sorter.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,18 @@ def items_from_label(
192192
with suppress(KeyError):
193193
node_ids = self.node_id_last[last_comp]
194194
for node_id in node_ids:
195-
if (node_id.endswith(label) or node_id.endswith("]") and
196-
node_id.rpartition("[")[0].endswith(label)):
195+
if node_id.endswith(label):
197196
id_start = node_id[:-label_len]
198-
if is_cls_mark and id_start.count("::") == 2:
199-
continue
200-
if item_id.startswith(id_start):
201-
items.append(self.node_ids[node_id])
197+
elif (node_id.endswith("]") and
198+
node_id.rpartition("[")[0].endswith(label)):
199+
id_start = node_id.rpartition("[")[0][:-label_len]
200+
else:
201+
continue
202+
if is_cls_mark and id_start.count("::") == 2:
203+
continue
204+
if item_id.startswith(id_start):
205+
items.append(self.node_ids[node_id])
206+
202207
return items
203208

204209
def items_from_class_label(self, label: str, item: Item) -> List[Item]:

tests/test_relative_ordering.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def test_dependency_on_parametrized_test(item_names_for):
501501
def test_1():
502502
pass
503503
504-
@pytest.mark.parametrize("arg", [1, 2, 3, 4])
504+
@pytest.mark.parametrize("arg", ["aaaaa", "bbbbb", "ccccc", "ddddd"])
505505
def test_2(arg):
506506
pass
507507
@@ -511,5 +511,6 @@ def test_3():
511511
"""
512512
)
513513
assert item_names_for(test_content) == [
514-
"test_3", "test_2[1]", "test_2[2]", "test_2[3]", "test_2[4]", "test_1"
514+
"test_3", "test_2[aaaaa]", "test_2[bbbbb]",
515+
"test_2[ccccc]", "test_2[ddddd]", "test_1"
515516
]

0 commit comments

Comments
 (0)