2015-01-28 20:35:27 +08:00
|
|
|
import sys
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 16:33:58 +08:00
|
|
|
|
2011-06-10 16:26:05 +08:00
|
|
|
from django.conf import settings
|
2007-08-16 14:06:55 +08:00
|
|
|
from django.core.management.base import BaseCommand
|
2018-08-17 03:49:03 +08:00
|
|
|
from django.core.management.utils import get_command_line_option
|
2011-06-10 16:26:05 +08:00
|
|
|
from django.test.utils import get_runner
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2013-03-25 12:34:46 +08:00
|
|
|
|
2007-08-16 14:06:55 +08:00
|
|
|
class Command(BaseCommand):
|
2014-06-07 02:12:23 +08:00
|
|
|
help = 'Discover and run tests in the specified modules or the current directory.'
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2016-03-18 22:24:13 +08:00
|
|
|
# DiscoverRunner runs the checks after databases are set up.
|
2014-01-20 10:45:21 +08:00
|
|
|
requires_system_checks = False
|
2017-09-07 20:10:49 +08:00
|
|
|
test_runner = None
|
2011-12-29 09:18:30 +08:00
|
|
|
|
2011-06-10 16:26:05 +08:00
|
|
|
def run_from_argv(self, argv):
|
|
|
|
"""
|
|
|
|
Pre-parse the command line to extract the value of the --testrunner
|
|
|
|
option. This allows a test runner to define additional command line
|
|
|
|
arguments.
|
|
|
|
"""
|
2018-08-17 03:49:03 +08:00
|
|
|
self.test_runner = get_command_line_option(argv, '--testrunner')
|
2017-01-21 21:13:44 +08:00
|
|
|
super().run_from_argv(argv)
|
2011-06-10 16:26:05 +08:00
|
|
|
|
2014-06-07 02:12:23 +08:00
|
|
|
def add_arguments(self, parser):
|
2016-03-29 06:33:29 +08:00
|
|
|
parser.add_argument(
|
|
|
|
'args', metavar='test_label', nargs='*',
|
|
|
|
help='Module paths to test; can be modulename, modulename.TestCase or modulename.TestCase.test_method'
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2017-04-02 08:03:56 +08:00
|
|
|
'--noinput', '--no-input', action='store_false', dest='interactive',
|
2016-03-29 06:33:29 +08:00
|
|
|
help='Tells Django to NOT prompt the user for input of any kind.',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2018-07-03 05:54:57 +08:00
|
|
|
'--failfast', action='store_true',
|
2016-03-29 06:33:29 +08:00
|
|
|
help='Tells Django to stop running the test suite after first failed test.',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2018-07-03 05:54:57 +08:00
|
|
|
'--testrunner',
|
2014-06-07 02:12:23 +08:00
|
|
|
help='Tells Django to use specified test runner class instead of '
|
2016-03-29 06:33:29 +08:00
|
|
|
'the one specified by the TEST_RUNNER setting.',
|
|
|
|
)
|
2014-06-07 02:12:23 +08:00
|
|
|
|
2011-06-10 16:26:05 +08:00
|
|
|
test_runner_class = get_runner(settings, self.test_runner)
|
2014-06-07 02:12:23 +08:00
|
|
|
|
|
|
|
if hasattr(test_runner_class, 'add_arguments'):
|
|
|
|
test_runner_class.add_arguments(parser)
|
2011-06-10 16:26:05 +08:00
|
|
|
|
2007-08-16 14:06:55 +08:00
|
|
|
def handle(self, *test_labels, **options):
|
2016-03-03 10:01:36 +08:00
|
|
|
TestRunner = get_runner(settings, options['testrunner'])
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2011-06-10 16:26:05 +08:00
|
|
|
test_runner = TestRunner(**options)
|
2011-04-02 16:37:53 +08:00
|
|
|
failures = test_runner.run_tests(test_labels)
|
2009-12-14 00:24:36 +08:00
|
|
|
|
2007-08-16 14:06:55 +08:00
|
|
|
if failures:
|
2016-11-03 19:40:59 +08:00
|
|
|
sys.exit(1)
|