1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #32914 -- Prevented test --shuffle from skipping test methods.

"test --shuffle" skipped test methods when test classes were mixed.
This changes runner.py's reorder_tests() to group by TestCase class.

Regression in 90ba716bf0.
This commit is contained in:
Chris Jerdonek
2021-07-09 16:12:17 -04:00
committed by Mariusz Felisiak
parent 6f60fa97b0
commit 5848b3a1d7
2 changed files with 43 additions and 8 deletions

View File

@@ -181,6 +181,19 @@ class TestSuiteTests(SimpleTestCase):
'Tests1.test1', 'Tests1.test2', 'Tests2.test2', 'Tests2.test1',
])
def test_reorder_tests_same_type_consecutive(self):
"""Tests of the same type are made consecutive."""
tests = self.make_tests()
# Move the last item to the front.
tests.insert(0, tests.pop())
self.assertTestNames(tests, expected=[
'Tests2.test2', 'Tests1.test1', 'Tests1.test2', 'Tests2.test1',
])
reordered_tests = reorder_tests(tests, classes=[])
self.assertTestNames(reordered_tests, expected=[
'Tests2.test2', 'Tests2.test1', 'Tests1.test1', 'Tests1.test2',
])
def test_reorder_tests_random(self):
tests = self.make_tests()
# Choose a seed that shuffles both the classes and methods.
@@ -191,6 +204,19 @@ class TestSuiteTests(SimpleTestCase):
'Tests2.test1', 'Tests2.test2', 'Tests1.test2', 'Tests1.test1',
])
def test_reorder_tests_random_mixed_classes(self):
tests = self.make_tests()
# Move the last item to the front.
tests.insert(0, tests.pop())
shuffler = Shuffler(seed=9)
self.assertTestNames(tests, expected=[
'Tests2.test2', 'Tests1.test1', 'Tests1.test2', 'Tests2.test1',
])
reordered_tests = reorder_tests(tests, classes=[], shuffler=shuffler)
self.assertTestNames(reordered_tests, expected=[
'Tests2.test1', 'Tests2.test2', 'Tests1.test2', 'Tests1.test1',
])
def test_reorder_tests_reverse_with_duplicates(self):
class Tests1(unittest.TestCase):
def test1(self):