Skip to content

Commit f2eff65

Browse files
committed
Hack to make the grouping tests pass.
This is probably busted, but the tests pass, so I think I need better tests.
1 parent 4a284c1 commit f2eff65

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

pytest_ordering/__init__.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,22 @@ def pytest_collection_modifyitems(session, config, items):
2626
items[:] = list(_order_tests(items))
2727

2828

29-
def orderable(marker):
30-
match = re.match('^order(\d+)$', marker)
31-
return bool(match) or marker in replacements
29+
def orderable(marker_name, marker_info):
30+
if not hasattr(marker_info, 'kwargs'):
31+
return False
32+
if 'order' in marker_info.kwargs:
33+
return True
34+
match = re.match('^order(\d+)$', marker_name)
35+
return bool(match) or marker_name in replacements
3236

3337

34-
def get_index(marker):
35-
match = re.match('^order(\d+)$', marker)
38+
def get_index(marker_name, marker_info):
39+
match = re.match('^order(\d+)$', marker_name)
3640
if match:
3741
return int(match.group(1)) - 1
38-
return replacements[marker]
42+
if marker_name in replacements:
43+
return replacements[marker_name]
44+
return marker_info.kwargs['order']
3945

4046

4147
def split(dictionary):
@@ -54,10 +60,11 @@ def _order_tests(tests):
5460
for test in tests:
5561
# There has got to be an API for this. :-/
5662
markers = test.keywords.__dict__['_markers']
57-
orderable_markers = [m for m in markers if orderable(m)]
63+
orderable_markers = [(k, v) for (k, v) in markers.items()
64+
if orderable(k, v)]
5865
if len(orderable_markers) == 1:
59-
[orderable_marker] = orderable_markers
60-
ordered_tests[get_index(orderable_marker)] = test
66+
marker_name, marker_info = orderable_markers[0]
67+
ordered_tests[get_index(marker_name, marker_info)] = test
6168
else:
6269
remaining_tests.append(test)
6370
from_beginning, from_end = split(ordered_tests)

tests/test_ordering.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ def get_order(output, test_file_name):
3535
# Default sorting is whatever order the tests show up in the module.
3636

3737
@pytest.mark.parametrize('module_name', [
38-
'numbers', 'words', 'words_backwards',
39-
# 'grouping', # This one is going to be tricky.
38+
'numbers', 'words', 'words_backwards', 'grouping',
4039
])
4140
def test_ordering(module_name, capsys):
4241
module = get_module(module_name)

0 commit comments

Comments
 (0)