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
|
2010-01-04 02:52:25 +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)
|
2010-01-18 23:11:01 +08:00
|
|
|
TestRunner = get_runner(settings)
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2010-01-18 23:11:01 +08:00
|
|
|
if hasattr(TestRunner, 'func_name'):
|
|
|
|
# Pre 1.2 test runners were just functions,
|
|
|
|
# and did not support the 'failfast' option.
|
|
|
|
import warnings
|
|
|
|
warnings.warn(
|
|
|
|
'Function-based test runners are deprecated. Test runners should be classes with a run_tests() method.',
|
|
|
|
PendingDeprecationWarning
|
|
|
|
)
|
|
|
|
failures = TestRunner(test_labels, verbosity=verbosity, interactive=interactive)
|
2009-12-14 00:24:36 +08:00
|
|
|
else:
|
2010-01-18 23:11:01 +08:00
|
|
|
test_runner = TestRunner(verbosity=verbosity, interactive=interactive, failfast=failfast)
|
|
|
|
failures = test_runner.run_tests(test_labels)
|
2009-12-14 00:24:36 +08:00
|
|
|
|
2007-08-16 14:06:55 +08:00
|
|
|
if failures:
|
2010-01-04 02:52:25 +08:00
|
|
|
sys.exit(bool(failures))
|