diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2011-06-10 08:26:05 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2011-06-10 08:26:05 +0000 |
| commit | 046ffa483ed63faae7b31e7e2cf618f88a3312ba (patch) | |
| tree | d90ffd710a4bbcd5db38469eb144efcb1c85e178 /django/core | |
| parent | b56ef75088e17fa3555766e92a6747411ccd738c (diff) | |
Fixed #16185, #15675 -- Added the ability for test runners to define custom options, and to specify a custom test runner at the command line. Thanks to Dmitry Jemerov and Mikołaj Siedlarek for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16352 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core')
| -rw-r--r-- | django/core/management/commands/test.py | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/django/core/management/commands/test.py b/django/core/management/commands/test.py index 1be1e1e768..1b3f2beada 100644 --- a/django/core/management/commands/test.py +++ b/django/core/management/commands/test.py @@ -1,29 +1,56 @@ +from django.conf import settings from django.core.management.base import BaseCommand -from optparse import make_option +from optparse import make_option, OptionParser import sys +from django.test.utils import get_runner class Command(BaseCommand): option_list = BaseCommand.option_list + ( make_option('--noinput', action='store_false', dest='interactive', default=True, help='Tells Django to NOT prompt the user for input of any kind.'), make_option('--failfast', action='store_true', dest='failfast', default=False, - help='Tells Django to stop running the test suite after first failed test.') + help='Tells Django to stop running the test suite after first failed test.'), + make_option('--testrunner', action='store', dest='testrunner', + help='Tells Django to use specified test runner class instead of the one '+ + 'specified by the TEST_RUNNER setting.') ) help = 'Runs the test suite for the specified applications, or the entire site if no apps are specified.' args = '[appname ...]' requires_model_validation = False + def run_from_argv(self, argv): + """ + Pre-parse the command line to extract the value of the --testrunner + option. This allows a test runner to define additional command line + arguments. + """ + self.test_runner = None + option = '--testrunner=' + for arg in argv[2:]: + if arg.startswith(option): + self.test_runner = arg[len(option):] + break + super(Command, self).run_from_argv(argv) + + def create_parser(self, prog_name, subcommand): + test_runner_class = get_runner(settings, self.test_runner) + options = self.option_list + getattr(test_runner_class, 'option_list', ()) + return OptionParser(prog=prog_name, + usage=self.usage(subcommand), + version=self.get_version(), + option_list=options) + def handle(self, *test_labels, **options): from django.conf import settings from django.test.utils import get_runner - verbosity = int(options.get('verbosity', 1)) - interactive = options.get('interactive', True) - failfast = options.get('failfast', False) - TestRunner = get_runner(settings) + TestRunner = get_runner(settings, options.get('testrunner')) + options['verbosity'] = int(options.get('verbosity', 1)) + options.setdefault('interactive', True) + options.setdefault('failfast', False) - test_runner = TestRunner(verbosity=verbosity, interactive=interactive, failfast=failfast) + test_runner = TestRunner(**options) failures = test_runner.run_tests(test_labels) if failures: |
