Return an iterator over the given tests in a shuffled order, keeping tests next to other tests of their class. `tests` should be an iterable of tests.
(tests, shuffler)
| 1191 | |
| 1192 | |
| 1193 | def shuffle_tests(tests, shuffler): |
| 1194 | """ |
| 1195 | Return an iterator over the given tests in a shuffled order, keeping tests |
| 1196 | next to other tests of their class. |
| 1197 | |
| 1198 | `tests` should be an iterable of tests. |
| 1199 | """ |
| 1200 | tests_by_type = {} |
| 1201 | for _, class_tests in itertools.groupby(tests, type): |
| 1202 | class_tests = list(class_tests) |
| 1203 | test_type = type(class_tests[0]) |
| 1204 | class_tests = shuffler.shuffle(class_tests, key=lambda test: test.id()) |
| 1205 | tests_by_type[test_type] = class_tests |
| 1206 | |
| 1207 | classes = shuffler.shuffle(tests_by_type, key=_class_shuffle_key) |
| 1208 | |
| 1209 | return itertools.chain(*(tests_by_type[cls] for cls in classes)) |
| 1210 | |
| 1211 | |
| 1212 | def reorder_test_bin(tests, shuffler=None, reverse=False): |