/tests/integration/lib/Django-1.2.5/django/core/management/commands/test.py

https://github.com/pokutnik/lettuce · Python · 40 lines · 32 code · 6 blank · 2 comment · 3 complexity · fbefe4eea4666b07acd2e3503662f6d0 MD5 · raw file

  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. make_option('--failfast', action='store_true', dest='failfast', default=False,
  9. help='Tells Django to stop running the test suite after first failed test.')
  10. )
  11. help = 'Runs the test suite for the specified applications, or the entire site if no apps are specified.'
  12. args = '[appname ...]'
  13. requires_model_validation = False
  14. def handle(self, *test_labels, **options):
  15. from django.conf import settings
  16. from django.test.utils import get_runner
  17. verbosity = int(options.get('verbosity', 1))
  18. interactive = options.get('interactive', True)
  19. failfast = options.get('failfast', False)
  20. TestRunner = get_runner(settings)
  21. if hasattr(TestRunner, 'func_name'):
  22. # Pre 1.2 test runners were just functions,
  23. # and did not support the 'failfast' option.
  24. import warnings
  25. warnings.warn(
  26. 'Function-based test runners are deprecated. Test runners should be classes with a run_tests() method.',
  27. PendingDeprecationWarning
  28. )
  29. failures = TestRunner(test_labels, verbosity=verbosity, interactive=interactive)
  30. else:
  31. test_runner = TestRunner(verbosity=verbosity, interactive=interactive, failfast=failfast)
  32. failures = test_runner.run_tests(test_labels)
  33. if failures:
  34. sys.exit(bool(failures))