4 |
4 |
5 class Command(BaseCommand): |
5 class Command(BaseCommand): |
6 option_list = BaseCommand.option_list + ( |
6 option_list = BaseCommand.option_list + ( |
7 make_option('--noinput', action='store_false', dest='interactive', default=True, |
7 make_option('--noinput', action='store_false', dest='interactive', default=True, |
8 help='Tells Django to NOT prompt the user for input of any kind.'), |
8 help='Tells Django to NOT prompt the user for input of any kind.'), |
|
9 make_option('--failfast', action='store_true', dest='failfast', default=False, |
|
10 help='Tells Django to stop running the test suite after first failed test.') |
9 ) |
11 ) |
10 help = 'Runs the test suite for the specified applications, or the entire site if no apps are specified.' |
12 help = 'Runs the test suite for the specified applications, or the entire site if no apps are specified.' |
11 args = '[appname ...]' |
13 args = '[appname ...]' |
12 |
14 |
13 requires_model_validation = False |
15 requires_model_validation = False |
16 from django.conf import settings |
18 from django.conf import settings |
17 from django.test.utils import get_runner |
19 from django.test.utils import get_runner |
18 |
20 |
19 verbosity = int(options.get('verbosity', 1)) |
21 verbosity = int(options.get('verbosity', 1)) |
20 interactive = options.get('interactive', True) |
22 interactive = options.get('interactive', True) |
21 test_runner = get_runner(settings) |
23 failfast = options.get('failfast', False) |
|
24 TestRunner = get_runner(settings) |
22 |
25 |
23 failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive) |
26 if hasattr(TestRunner, 'func_name'): |
|
27 # Pre 1.2 test runners were just functions, |
|
28 # and did not support the 'failfast' option. |
|
29 import warnings |
|
30 warnings.warn( |
|
31 'Function-based test runners are deprecated. Test runners should be classes with a run_tests() method.', |
|
32 PendingDeprecationWarning |
|
33 ) |
|
34 failures = TestRunner(test_labels, verbosity=verbosity, interactive=interactive) |
|
35 else: |
|
36 test_runner = TestRunner(verbosity=verbosity, interactive=interactive, failfast=failfast) |
|
37 failures = test_runner.run_tests(test_labels) |
|
38 |
24 if failures: |
39 if failures: |
25 sys.exit(failures) |
40 sys.exit(bool(failures)) |