#35183: tests - add a new argument "--test-only" ---------------------------------------------+------------------------ Reporter: אורי | Owner: nobody Type: New feature | Status: new Component: Testing framework | Version: Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | ---------------------------------------------+------------------------ 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. :-) -- Ticket URL: <https://code.djangoproject.com/ticket/35183> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018d9b59238f-e52feea1-1bb8-4f25-9d31-55aeede2a853-000000%40eu-central-1.amazonses.com.