Skip to content

Commit 2ca0870

Browse files
committed
Fixed #23992 -- Optimized reorder_suite functions using OrderedSet
1 parent 71a559e commit 2ca0870

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

django/test/runner.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django.core.exceptions import ImproperlyConfigured
88
from django.test import SimpleTestCase, TestCase
99
from django.test.utils import setup_test_environment, teardown_test_environment
10+
from django.utils.datastructures import OrderedSet
1011

1112

1213
class DiscoverRunner(object):
@@ -231,11 +232,12 @@ def reorder_suite(suite, classes, reverse=False):
231232
"""
232233
class_count = len(classes)
233234
suite_class = type(suite)
234-
bins = [suite_class() for i in range(class_count + 1)]
235+
bins = [OrderedSet() for i in range(class_count + 1)]
235236
partition_suite(suite, classes, bins, reverse=reverse)
236-
for i in range(class_count):
237-
bins[0].addTests(bins[i + 1])
238-
return bins[0]
237+
reordered_suite = suite_class()
238+
for i in range(class_count + 1):
239+
reordered_suite.addTests(bins[i])
240+
return reordered_suite
239241

240242

241243
def partition_suite(suite, classes, bins, reverse=False):
@@ -258,12 +260,10 @@ def partition_suite(suite, classes, bins, reverse=False):
258260
else:
259261
for i in range(len(classes)):
260262
if isinstance(test, classes[i]):
261-
if test not in bins[i]:
262-
bins[i].addTest(test)
263+
bins[i].add(test)
263264
break
264265
else:
265-
if test not in bins[-1]:
266-
bins[-1].addTest(test)
266+
bins[-1].add(test)
267267

268268

269269
def setup_databases(verbosity, interactive, keepdb=False, **kwargs):

0 commit comments

Comments
 (0)