test.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. from django.core.management.base import BaseCommand
  2. from optparse import make_option
  3. import sys
  4. class Command(BaseCommand):
  5. option_list = BaseCommand.option_list + (
  6. make_option('--noinput', action='store_false', dest='interactive', default=True,
  7. help='Tells Django to NOT prompt the user for input of any kind.'),
  8. )
  9. help = 'Runs the test suite for the specified applications, or the entire site if no apps are specified.'
  10. args = '[appname ...]'
  11. requires_model_validation = False
  12. def handle(self, *test_labels, **options):
  13. from django.conf import settings
  14. verbosity = int(options.get('verbosity', 1))
  15. interactive = options.get('interactive', True)
  16. test_path = settings.TEST_RUNNER.split('.')
  17. # Allow for Python 2.5 relative paths
  18. if len(test_path) > 1:
  19. test_module_name = '.'.join(test_path[:-1])
  20. else:
  21. test_module_name = '.'
  22. test_module = __import__(test_module_name, {}, {}, test_path[-1])
  23. test_runner = getattr(test_module, test_path[-1])
  24. failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive)
  25. if failures:
  26. sys.exit(failures)