summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2021-03-05 20:03:35 -0800
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-03-08 09:53:31 +0100
commitcc12894017c3b941c51f80b8d8e50da758f67802 (patch)
tree49d3fbe06e95d272a95d5e99be7900f2660c7dba
parent2e5aa444d140a9f2bc858e493ff85ced589f1a58 (diff)
Refs #32489 -- Removed unneeded partition_suite_by_type().
-rw-r--r--django/test/runner.py35
1 files changed, 10 insertions, 25 deletions
diff --git a/django/test/runner.py b/django/test/runner.py
index 20bc93fca7..02306090ea 100644
--- a/django/test/runner.py
+++ b/django/test/runner.py
@@ -766,7 +766,7 @@ def is_discoverable(label):
def reorder_suite(suite, classes, reverse=False):
"""
- Reorder a test suite by test type.
+ Reorder a test suite by test type, removing any duplicates.
`classes` is a sequence of types
@@ -776,34 +776,19 @@ def reorder_suite(suite, classes, reverse=False):
If `reverse` is True, sort tests within classes in opposite order but
don't reverse test classes.
"""
- class_count = len(classes)
- suite_class = type(suite)
- bins = [OrderedSet() for i in range(class_count + 1)]
- partition_suite_by_type(suite, classes, bins, reverse=reverse)
- reordered_suite = suite_class()
- for tests in bins:
- reordered_suite.addTests(tests)
- return reordered_suite
-
-
-def partition_suite_by_type(suite, classes, bins, reverse=False):
- """
- Partition a test suite by test type. Also prevent duplicated tests.
+ bins = [OrderedSet() for i in range(len(classes) + 1)]
+ *class_bins, last_bin = bins
- classes is a sequence of types
- bins is a sequence of TestSuites, one more than classes
- reverse changes the ordering of tests within bins
-
- Tests of type classes[i] are added to bins[i],
- tests with no match found in classes are place in bins[-1]
- """
for test in iter_test_cases(suite, reverse=reverse):
- for i in range(len(classes)):
- if isinstance(test, classes[i]):
- bins[i].add(test)
+ for test_bin, test_class in zip(class_bins, classes):
+ if isinstance(test, test_class):
break
else:
- bins[-1].add(test)
+ test_bin = last_bin
+ test_bin.add(test)
+
+ suite_class = type(suite)
+ return suite_class(itertools.chain(*bins))
def partition_suite_by_case(suite):