MCPcopy
hub / github.com/django/django / reorder_tests

Function reorder_tests

django/test/runner.py:1232–1268  ·  view source on GitHub ↗

Reorder an iterable of tests, grouping by the given TestCase classes. This function also removes any duplicates and reorders so that tests of the same type are consecutive. The result is returned as an iterator. `classes` is a sequence of types. Tests that are instances of `cl

(tests, classes, reverse=False, shuffler=None)

Source from the content-addressed store, hash-verified

1230
1231
1232def reorder_tests(tests, classes, reverse=False, shuffler=None):
1233 """
1234 Reorder an iterable of tests, grouping by the given TestCase classes.
1235
1236 This function also removes any duplicates and reorders so that tests of the
1237 same type are consecutive.
1238
1239 The result is returned as an iterator. `classes` is a sequence of types.
1240 Tests that are instances of `classes[0]` are grouped first, followed by
1241 instances of `classes[1]`, etc. Tests that are not instances of any of the
1242 classes are grouped last.
1243
1244 If `reverse` is True, the tests within each `classes` group are reversed,
1245 but without reversing the order of `classes` itself.
1246
1247 The `shuffler` argument is an optional instance of this module's `Shuffler`
1248 class. If provided, tests will be shuffled within each `classes` group, but
1249 keeping tests with other tests of their TestCase class. Reversing is
1250 applied after shuffling to allow reversing the same random order.
1251 """
1252 # Each bin maps TestCase class to OrderedSet of tests. This permits tests
1253 # to be grouped by TestCase class even if provided non-consecutively.
1254 bins = [defaultdict(OrderedSet) for i in range(len(classes) + 1)]
1255 *class_bins, last_bin = bins
1256
1257 for test in tests:
1258 for test_bin, test_class in zip(class_bins, classes):
1259 if isinstance(test, test_class):
1260 break
1261 else:
1262 test_bin = last_bin
1263 test_bin[type(test)].add(test)
1264
1265 for test_bin in bins:
1266 # Call list() since reorder_test_bin()'s input must support reversed().
1267 tests = list(itertools.chain.from_iterable(test_bin.values()))
1268 yield from reorder_test_bin(tests, shuffler=shuffler, reverse=reverse)
1269
1270
1271def partition_suite_by_case(suite):

Calls 3

reorder_test_binFunction · 0.85
addMethod · 0.45
valuesMethod · 0.45