1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #32516 -- Fixed reorder_suite() with duplicates and reverse=True.

This commit is contained in:
Chris Jerdonek
2021-03-08 07:06:03 -08:00
committed by Mariusz Felisiak
parent 98d3fd6102
commit 77e0a35a10
3 changed files with 55 additions and 28 deletions

View File

@@ -779,7 +779,7 @@ def reorder_suite(suite, classes, reverse=False):
bins = [OrderedSet() for i in range(len(classes) + 1)]
*class_bins, last_bin = bins
for test in iter_test_cases(suite, reverse=reverse):
for test in iter_test_cases(suite):
for test_bin, test_class in zip(class_bins, classes):
if isinstance(test, test_class):
break
@@ -787,6 +787,8 @@ def reorder_suite(suite, classes, reverse=False):
test_bin = last_bin
test_bin.add(test)
if reverse:
bins = (reversed(tests) for tests in bins)
suite_class = type(suite)
return suite_class(itertools.chain(*bins))

View File

@@ -235,16 +235,14 @@ def setup_databases(
return old_names
def iter_test_cases(suite, reverse=False):
def iter_test_cases(suite):
"""Return an iterator over a test suite's unittest.TestCase objects."""
if reverse:
suite = reversed(tuple(suite))
for test in suite:
if isinstance(test, TestCase):
yield test
else:
# Otherwise, assume it is a test suite.
yield from iter_test_cases(test, reverse=reverse)
yield from iter_test_cases(test)
def dependency_ordered(test_databases, dependencies):