2007-08-16 14:06:55 +08:00
|
|
|
from django.core.management.base import BaseCommand
|
2007-09-10 05:57:59 +08:00
|
|
|
from optparse import make_option
|
2007-08-16 19:06:49 +08:00
|
|
|
import sys
|
2007-08-16 14:06:55 +08:00
|
|
|
|
|
|
|
class Command(BaseCommand):
|
2007-09-10 05:57:59 +08:00
|
|
|
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.'),
|
2009-12-14 00:24:36 +08:00
|
|
|
make_option('--failfast', action='store_true', dest='failfast', default=False,
|
|
|
|
help='Tells Django to stop running the test suite after first failed test.')
|
2007-09-10 05:57:59 +08:00
|
|
|
)
|
2007-08-16 14:06:55 +08:00
|
|
|
help = 'Runs the test suite for the specified applications, or the entire site if no apps are specified.'
|
2007-09-10 05:57:59 +08:00
|
|
|
args = '[appname ...]'
|
2007-08-16 14:06:55 +08:00
|
|
|
|
|
|
|
requires_model_validation = False
|
|
|
|
|
|
|
|
def handle(self, *test_labels, **options):
|
|
|
|
from django.conf import settings
|
2009-02-28 12:46:38 +08:00
|
|
|
from django.test.utils import get_runner
|
2009-12-14 00:24:36 +08:00
|
|
|
|
2007-08-17 08:11:56 +08:00
|
|
|
verbosity = int(options.get('verbosity', 1))
|
2007-08-16 14:06:55 +08:00
|
|
|
interactive = options.get('interactive', True)
|
2009-12-14 00:24:36 +08:00
|
|
|
failfast = options.get('failfast', False)
|
2009-02-28 12:46:38 +08:00
|
|
|
test_runner = get_runner(settings)
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2009-12-14 00:24:36 +08:00
|
|
|
# Some custom test runners won't accept the failfast flag, so let's make sure they accept it before passing it to them
|
|
|
|
if 'failfast' in test_runner.func_code.co_varnames:
|
|
|
|
failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive,
|
|
|
|
failfast=failfast)
|
|
|
|
else:
|
|
|
|
failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive)
|
|
|
|
|
2007-08-16 14:06:55 +08:00
|
|
|
if failures:
|
|
|
|
sys.exit(failures)
|