Fixed #23992 -- Optimized reorder_suite functions using OrderedSet
This commit is contained in:
parent
71a559e771
commit
2ca0870b67
|
@ -7,6 +7,7 @@ from django.conf import settings
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.test import SimpleTestCase, TestCase
|
from django.test import SimpleTestCase, TestCase
|
||||||
from django.test.utils import setup_test_environment, teardown_test_environment
|
from django.test.utils import setup_test_environment, teardown_test_environment
|
||||||
|
from django.utils.datastructures import OrderedSet
|
||||||
|
|
||||||
|
|
||||||
class DiscoverRunner(object):
|
class DiscoverRunner(object):
|
||||||
|
@ -231,11 +232,12 @@ def reorder_suite(suite, classes, reverse=False):
|
||||||
"""
|
"""
|
||||||
class_count = len(classes)
|
class_count = len(classes)
|
||||||
suite_class = type(suite)
|
suite_class = type(suite)
|
||||||
bins = [suite_class() for i in range(class_count + 1)]
|
bins = [OrderedSet() for i in range(class_count + 1)]
|
||||||
partition_suite(suite, classes, bins, reverse=reverse)
|
partition_suite(suite, classes, bins, reverse=reverse)
|
||||||
for i in range(class_count):
|
reordered_suite = suite_class()
|
||||||
bins[0].addTests(bins[i + 1])
|
for i in range(class_count + 1):
|
||||||
return bins[0]
|
reordered_suite.addTests(bins[i])
|
||||||
|
return reordered_suite
|
||||||
|
|
||||||
|
|
||||||
def partition_suite(suite, classes, bins, reverse=False):
|
def partition_suite(suite, classes, bins, reverse=False):
|
||||||
|
@ -258,12 +260,10 @@ def partition_suite(suite, classes, bins, reverse=False):
|
||||||
else:
|
else:
|
||||||
for i in range(len(classes)):
|
for i in range(len(classes)):
|
||||||
if isinstance(test, classes[i]):
|
if isinstance(test, classes[i]):
|
||||||
if test not in bins[i]:
|
bins[i].add(test)
|
||||||
bins[i].addTest(test)
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if test not in bins[-1]:
|
bins[-1].add(test)
|
||||||
bins[-1].addTest(test)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_databases(verbosity, interactive, keepdb=False, **kwargs):
|
def setup_databases(verbosity, interactive, keepdb=False, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue