MCPcopy
hub / github.com/django/django / shuffle_tests

Function shuffle_tests

django/test/runner.py:1193–1209  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1191
1192
1193def 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
1212def reorder_test_bin(tests, shuffler=None, reverse=False):

Callers 2

test_shuffle_testsMethod · 0.90
reorder_test_binFunction · 0.85

Calls 2

shuffleMethod · 0.80
chainMethod · 0.45

Tested by 1

test_shuffle_testsMethod · 0.72