24
24
25
25
26
26
def pytest_configure (config ):
27
- """Register the "run" marker.
28
- """
27
+ """Register the "run" marker."""
28
+
29
29
config_line = (
30
30
'run: specify ordering information for when tests should run '
31
31
'in relation to one another. Provided by pytest-ordering. '
@@ -41,19 +41,22 @@ def pytest_collection_modifyitems(session, config, items):
41
41
def orderable (marker_name , marker_info ):
42
42
if not hasattr (marker_info , 'kwargs' ):
43
43
return False
44
- if 'order' in marker_info .kwargs :
44
+ elif 'order' in marker_info .kwargs :
45
45
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
48
49
49
50
50
51
def get_index (marker_name , marker_info ):
51
52
match = re .match ('^order(\d+)$' , marker_name )
53
+
52
54
if match :
53
55
return int (match .group (1 )) - 1
54
- if marker_name in replacements :
56
+ elif marker_name in replacements :
55
57
return replacements [marker_name ]
56
- return marker_info .kwargs ['order' ]
58
+ else :
59
+ return marker_info .kwargs ['order' ]
57
60
58
61
59
62
def split (dictionary ):
@@ -69,6 +72,7 @@ def split(dictionary):
69
72
def _order_tests (tests ):
70
73
ordered_tests = defaultdict (list )
71
74
remaining_tests = []
75
+
72
76
for test in tests :
73
77
# There has got to be an API for this. :-/
74
78
markers = test .keywords .__dict__ ['_markers' ]
@@ -79,20 +83,18 @@ def _order_tests(tests):
79
83
ordered_tests [get_index (marker_name , marker_info )].append (test )
80
84
else :
81
85
remaining_tests .append (test )
86
+
82
87
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 :
98
100
yield test
0 commit comments