Skip to content

Commit a29a07f

Browse files
refactoring
1 parent 81bfe73 commit a29a07f

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

pytest_ordering/__init__.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525

2626
def pytest_configure(config):
27-
"""Register the "run" marker.
28-
"""
27+
"""Register the "run" marker."""
28+
2929
config_line = (
3030
'run: specify ordering information for when tests should run '
3131
'in relation to one another. Provided by pytest-ordering. '
@@ -41,19 +41,22 @@ def pytest_collection_modifyitems(session, config, items):
4141
def orderable(marker_name, marker_info):
4242
if not hasattr(marker_info, 'kwargs'):
4343
return False
44-
if 'order' in marker_info.kwargs:
44+
elif 'order' in marker_info.kwargs:
4545
return True
46-
match = re.match('^order(\d+)$', marker_name)
47-
return bool(match) or marker_name in replacements
46+
else:
47+
match = re.match('^order(\d+)$', marker_name)
48+
return bool(match) or marker_name in replacements
4849

4950

5051
def get_index(marker_name, marker_info):
5152
match = re.match('^order(\d+)$', marker_name)
53+
5254
if match:
5355
return int(match.group(1)) - 1
54-
if marker_name in replacements:
56+
elif marker_name in replacements:
5557
return replacements[marker_name]
56-
return marker_info.kwargs['order']
58+
else:
59+
return marker_info.kwargs['order']
5760

5861

5962
def split(dictionary):
@@ -69,6 +72,7 @@ def split(dictionary):
6972
def _order_tests(tests):
7073
ordered_tests = defaultdict(list)
7174
remaining_tests = []
75+
7276
for test in tests:
7377
# There has got to be an API for this. :-/
7478
markers = test.keywords.__dict__['_markers']
@@ -79,20 +83,18 @@ def _order_tests(tests):
7983
ordered_tests[get_index(marker_name, marker_info)].append(test)
8084
else:
8185
remaining_tests.append(test)
86+
8287
from_beginning, from_end = split(ordered_tests)
83-
remaining_iter = iter(remaining_tests)
84-
for i in range(max(from_beginning or [-1]) + 1):
85-
if i in from_beginning:
86-
for e in from_beginning[i]:
87-
yield e
88-
else:
89-
yield next(remaining_iter)
90-
# TODO TODO TODO
91-
for i in range(min(from_end or [0]), 0):
92-
if i in from_end:
93-
for e in from_end[i]:
94-
yield e
95-
else:
96-
yield next(remaining_iter)
97-
for test in remaining_iter:
88+
89+
# run test from beginning
90+
for test_order in sorted(from_beginning):
91+
for test in from_beginning[test_order]:
92+
yield test
93+
94+
# run test from end
95+
for test_order in sorted(from_end, reverse=True):
96+
for test in from_end[test_order]:
97+
yield test
98+
99+
for test in remaining_tests:
98100
yield test

0 commit comments

Comments
 (0)