Opened 3 months ago

Closed 3 months ago

#35183 closed New feature (wontfix)

Run only a random subset of tests.

Reported by: אורי Owned by: nobody
Component: Testing framework Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

tests - add a new argument "--test-only" (int, >=0) and If run with this argument, run only this number of tests.

Sometimes there are thousands of tests, for example 6,000 tests, and I want to run only a random subset of them, for example 200 tests. It should be possible with Django.

The code needed to implement such a feature is:

In command test:

        parser.add_argument(
            "--test-only",
            action="store",
            help="If run with this argument, run only this number of tests.",
            type=int,
        )

In DiscoverRunner::init:

            self.test_only = kwargs.get('test_only', None)
            if (self.test_only is not None):
                assert (self.test_only >= 0)

In DiscoverRunner::test_suite:

        def test_suite(self, tests=()):
            if (self.test_only is not None):
                tests = tests[:self.test_only]
            return super().test_suite(tests=tests)

Usage:

python manage.py test --shuffle --test-only 200

(It makes more sense to use it with --shuffle, but you can also use it without it).

And that's all. :-)

Change History (1)

comment:1 by Mariusz Felisiak, 3 months ago

Resolution: wontfix
Status: newclosed
Summary: tests - add a new argument "--test-only"Run only a random subset of tests.
Version: dev

Thanks for this ticket, however, I think it's a bit of a niche case. The current thread is to keep Django a core framework, not providing every utility which might be useful.

Please first start a discussion on the DevelopersMailingList, where you'll reach a wider audience and see what other think, and follow the guidelines with regards to wontfix tickets.

Note: See TracTickets for help on using tickets.
Back to Top