|
0
|
1 |
from django.core.management.base import BaseCommand |
|
|
2 |
from optparse import make_option |
|
|
3 |
import sys |
|
|
4 |
|
|
|
5 |
class Command(BaseCommand): |
|
|
6 |
option_list = BaseCommand.option_list + ( |
|
|
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.'), |
|
29
|
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.') |
|
0
|
11 |
) |
|
|
12 |
help = 'Runs the test suite for the specified applications, or the entire site if no apps are specified.' |
|
|
13 |
args = '[appname ...]' |
|
|
14 |
|
|
|
15 |
requires_model_validation = False |
|
|
16 |
|
|
|
17 |
def handle(self, *test_labels, **options): |
|
|
18 |
from django.conf import settings |
|
|
19 |
from django.test.utils import get_runner |
|
|
20 |
|
|
|
21 |
verbosity = int(options.get('verbosity', 1)) |
|
|
22 |
interactive = options.get('interactive', True) |
|
29
|
23 |
failfast = options.get('failfast', False) |
|
|
24 |
TestRunner = get_runner(settings) |
|
0
|
25 |
|
|
29
|
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 |
|
|
0
|
39 |
if failures: |
|
29
|
40 |
sys.exit(bool(failures)) |