Fixed #23707 -- Prevented discovery of duplicated tests
This commit is contained in:
parent
92269b7b53
commit
2c9a03d487
|
@ -233,7 +233,7 @@ def reorder_suite(suite, classes):
|
||||||
|
|
||||||
def partition_suite(suite, classes, bins):
|
def partition_suite(suite, classes, bins):
|
||||||
"""
|
"""
|
||||||
Partitions a test suite by test type.
|
Partitions a test suite by test type. Also prevents duplicated tests.
|
||||||
|
|
||||||
classes is a sequence of types
|
classes is a sequence of types
|
||||||
bins is a sequence of TestSuites, one more than classes
|
bins is a sequence of TestSuites, one more than classes
|
||||||
|
@ -248,9 +248,11 @@ def partition_suite(suite, classes, bins):
|
||||||
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].addTest(test)
|
bins[i].addTest(test)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
if test not in bins[-1]:
|
||||||
bins[-1].addTest(test)
|
bins[-1].addTest(test)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,15 @@ class DiscoverRunnerTest(TestCase):
|
||||||
# All others can follow in unspecified order, including doctests
|
# All others can follow in unspecified order, including doctests
|
||||||
self.assertIn('DocTestCase', [t.__class__.__name__ for t in suite._tests[2:]])
|
self.assertIn('DocTestCase', [t.__class__.__name__ for t in suite._tests[2:]])
|
||||||
|
|
||||||
|
def test_duplicates_ignored(self):
|
||||||
|
"""
|
||||||
|
Tests shouldn't be discovered twice when discovering on overlapping paths.
|
||||||
|
"""
|
||||||
|
single = DiscoverRunner().build_suite(["django.contrib.gis"]).countTestCases()
|
||||||
|
dups = DiscoverRunner().build_suite(
|
||||||
|
["django.contrib.gis", "django.contrib.gis.tests.geo3d"]).countTestCases()
|
||||||
|
self.assertEqual(single, dups)
|
||||||
|
|
||||||
def test_overrideable_test_suite(self):
|
def test_overrideable_test_suite(self):
|
||||||
self.assertEqual(DiscoverRunner().test_suite, TestSuite)
|
self.assertEqual(DiscoverRunner().test_suite, TestSuite)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue