﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35183	Run only a random subset of tests.	אורי	nobody	"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. :-)"	New feature	closed	Testing framework	dev	Normal	wontfix			Unreviewed	0	0	0	0	0	0
