I'd like to ask folks if they would support reopening ticket #24522, which
is to add a --random option to Django's test runner:
https://code.djangoproject.com/ticket/24522

It was opened 6 years ago and closed as won't fix.

I've been doing some simplifications of the test-suite related code in
Django's DiscoverRunner, and I think a --random option could be added
pretty simply. It seems like every project could benefit by running their
tests in a random order. It would help to unearth hidden dependencies
between tests.

If I were to implement this, the --random option would accept an optional
integer "seed" argument. If --random is passed with no seed argument, the
seed would be generated randomly by choosing a random integer between 0 and
some large integer. Whether or not an explicit seed value is passed, Django
can log the seed value being used before running tests (if --random was
passed), and DiscoverRunner can store the seed as an attribute like
self.random_order_seed. That would give callers the option of doing
something with the seed programmatically, if logging to stderr isn't enough.

When --random is used, the order of classes can be randomized within their
groups:
https://docs.djangoproject.com/en/3.1/topics/testing/overview/#order-in-which-tests-are-executed
and the order of methods within their class can also be randomized.

The seed can be used by instantiating a Python random.Random() object with
it:
https://docs.python.org/3/library/random.html#random.Random
and the random orders could be generated by calling methods of that
now-deterministic object.

--Chris

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAOTb1wd7YnjmLwS_Gvvj3iGOx_Oodp7Xv%2BwZb_tCJ2Qmy%2BHO5g%40mail.gmail.com.
  • req... Chris Jerdonek
    • ... 'Adam Johnson' via Django developers (Contributions to Django itself)
      • ... Mariusz Felisiak
        • ... Fran Hrženjak
          • ... Mariusz Felisiak
            • ... chris.j...@gmail.com
              • ... Florian Apolloner
                • ... Florian Apolloner
                • ... Chris Jerdonek
                • ... Florian Apolloner
                • ... 'Adam Johnson' via Django developers (Contributions to Django itself)

Reply via email to