Fixed #24522 -- Added a --shuffle option to DiscoverRunner.

This commit is contained in:
Chris Jerdonek 2021-04-24 16:46:16 -07:00 committed by Mariusz Felisiak
parent 77b88fe621
commit 90ba716bf0
10 changed files with 472 additions and 21 deletions

View file

@ -1425,11 +1425,30 @@ subsequent run. Unless the :setting:`MIGRATE <TEST_MIGRATE>` test setting is
``False``, any unapplied migrations will also be applied to the test database
before running the test suite.
.. django-admin-option:: --shuffle [SEED]
.. versionadded:: 4.0
Randomizes the order of tests before running them. This can help detect tests
that aren't properly isolated. The test order generated by this option is a
deterministic function of the integer seed given. When no seed is passed, a
seed is chosen randomly and printed to the console. To repeat a particular test
order, pass a seed. The test orders generated by this option preserve Django's
:ref:`guarantees on test order <order-of-tests>`. They also keep tests grouped
by test case class.
The shuffled orderings also have a special consistency property useful when
narrowing down isolation issues. Namely, for a given seed and when running a
subset of tests, the new order will be the original shuffling restricted to the
smaller set. Similarly, when adding tests while keeping the seed the same, the
order of the original tests will be the same in the new order.
.. django-admin-option:: --reverse, -r
Sorts test cases in the opposite execution order. This may help in debugging
the side effects of tests that aren't properly isolated. :ref:`Grouping by test
class <order-of-tests>` is preserved when using this option.
class <order-of-tests>` is preserved when using this option. This can be used
in conjunction with ``--shuffle`` to reverse the order for a particular seed.
.. django-admin-option:: --debug-mode