Skip to content

Commit ec6c906

Browse files
xiekeyangdianpopa
authored andcommitted
tests: refactor batch assignment mechanism
Simplified the mechanism for finding the matching batch inside the scheduler for each of the tests. The mechanism (i.e next) stops the iteration when the matching batch is found based on some given regex search. Signed-off-by: keyangxie <[email protected]>
1 parent 57ac9df commit ec6c906

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

tests/framework/scheduler.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,16 @@ def pytest_runtestloop(self, session):
150150
# Go through the list of tests and assign each of them to its
151151
# corresponding batch in the schedule.
152152
for item in session.items:
153-
for batch in schedule:
154-
# A test can match any of the patterns defined by the batch,
155-
# in order to get assigned to it.
156-
re_pattern = "|".join(
157-
["({})".format(x) for x in batch['patterns']]
158-
)
159-
item_full_name = "/".join(item.listnames())
160-
if re.search(re_pattern, item_full_name) is not None:
161-
# Found a matching batch. No need to look any further.
162-
batch['items'].append(item)
163-
break
153+
# A test can match any of the patterns defined by the batch,
154+
# in order to get assigned to it.
155+
next(
156+
# Found a matching batch. No need to look any further.
157+
batch['items'].append(item) for batch in schedule
158+
if re.search(
159+
"|".join(["({})".format(x) for x in batch['patterns']]),
160+
"/".join(item.listnames()),
161+
) is not None
162+
)
164163

165164
# Filter out empty batches.
166165
schedule = [batch for batch in schedule if batch['items']]

0 commit comments

Comments
 (0)