app/django/core/management/commands/test.py
changeset 54 03e267d67478
child 323 ff1a9aa48cfd
equal deleted inserted replaced
53:57b4279d8c4e 54:03e267d67478
       
     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('--verbosity', action='store', dest='verbosity', default='1',
       
     8             type='choice', choices=['0', '1', '2'],
       
     9             help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
       
    10         make_option('--noinput', action='store_false', dest='interactive', default=True,
       
    11             help='Tells Django to NOT prompt the user for input of any kind.'),
       
    12     )
       
    13     help = 'Runs the test suite for the specified applications, or the entire site if no apps are specified.'
       
    14     args = '[appname ...]'
       
    15 
       
    16     requires_model_validation = False
       
    17 
       
    18     def handle(self, *test_labels, **options):
       
    19         from django.conf import settings
       
    20         from django.db.models import get_app, get_apps
       
    21 
       
    22         verbosity = int(options.get('verbosity', 1))
       
    23         interactive = options.get('interactive', True)
       
    24     
       
    25         test_path = settings.TEST_RUNNER.split('.')
       
    26         # Allow for Python 2.5 relative paths
       
    27         if len(test_path) > 1:
       
    28             test_module_name = '.'.join(test_path[:-1])
       
    29         else:
       
    30             test_module_name = '.'
       
    31         test_module = __import__(test_module_name, {}, {}, test_path[-1])
       
    32         test_runner = getattr(test_module, test_path[-1])
       
    33 
       
    34         failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive)
       
    35         if failures:
       
    36             sys.exit(failures)