2013-03-25 12:34:46 +08:00
|
|
|
import logging
|
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
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
from optparse import make_option, OptionParser
|
|
|
|
|
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
|
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):
|
2007-09-10 05:57:59 +08:00
|
|
|
option_list = BaseCommand.option_list + (
|
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
|
|
|
make_option('--noinput',
|
|
|
|
action='store_false', dest='interactive', default=True,
|
2007-09-10 05:57:59 +08:00
|
|
|
help='Tells Django to NOT prompt the user for input of any kind.'),
|
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
|
|
|
make_option('--failfast',
|
|
|
|
action='store_true', dest='failfast', default=False,
|
|
|
|
help='Tells Django to stop running the test suite after first '
|
|
|
|
'failed test.'),
|
|
|
|
make_option('--testrunner',
|
|
|
|
action='store', dest='testrunner',
|
|
|
|
help='Tells Django to use specified test runner class instead of '
|
|
|
|
'the one specified by the TEST_RUNNER setting.'),
|
|
|
|
make_option('--liveserver',
|
|
|
|
action='store', dest='liveserver', default=None,
|
|
|
|
help='Overrides the default address where the live server (used '
|
|
|
|
'with LiveServerTestCase) is expected to run from. The '
|
|
|
|
'default value is localhost:8081.'),
|
2007-09-10 05:57:59 +08:00
|
|
|
)
|
2013-09-03 23:50:34 +08:00
|
|
|
help = ('Discover and run tests in the specified modules or the current directory.')
|
|
|
|
args = '[path.to.modulename|path.to.modulename.TestCase|path.to.modulename.TestCase.test_method]...'
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2014-01-20 10:45:21 +08:00
|
|
|
requires_system_checks = False
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2011-12-29 09:18:30 +08:00
|
|
|
def __init__(self):
|
|
|
|
self.test_runner = None
|
|
|
|
super(Command, self).__init__()
|
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
option = '--testrunner='
|
|
|
|
for arg in argv[2:]:
|
|
|
|
if arg.startswith(option):
|
|
|
|
self.test_runner = arg[len(option):]
|
|
|
|
break
|
|
|
|
super(Command, self).run_from_argv(argv)
|
|
|
|
|
|
|
|
def create_parser(self, prog_name, subcommand):
|
|
|
|
test_runner_class = get_runner(settings, self.test_runner)
|
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
|
|
|
options = self.option_list + getattr(
|
|
|
|
test_runner_class, 'option_list', ())
|
2011-06-10 16:26:05 +08:00
|
|
|
return OptionParser(prog=prog_name,
|
|
|
|
usage=self.usage(subcommand),
|
|
|
|
version=self.get_version(),
|
|
|
|
option_list=options)
|
|
|
|
|
2013-03-25 12:34:46 +08:00
|
|
|
def execute(self, *args, **options):
|
|
|
|
if int(options['verbosity']) > 0:
|
|
|
|
# ensure that deprecation warnings are displayed during testing
|
|
|
|
# the following state is assumed:
|
|
|
|
# logging.capturewarnings is true
|
|
|
|
# a "default" level warnings filter has been added for
|
|
|
|
# DeprecationWarning. See django.conf.LazySettings._configure_logging
|
|
|
|
logger = logging.getLogger('py.warnings')
|
|
|
|
handler = logging.StreamHandler()
|
|
|
|
logger.addHandler(handler)
|
|
|
|
super(Command, self).execute(*args, **options)
|
|
|
|
if int(options['verbosity']) > 0:
|
|
|
|
# remove the testing-specific handler
|
|
|
|
logger.removeHandler(handler)
|
|
|
|
|
2007-08-16 14:06:55 +08:00
|
|
|
def handle(self, *test_labels, **options):
|
|
|
|
from django.conf import settings
|
2009-02-28 12:46:38 +08:00
|
|
|
from django.test.utils import get_runner
|
2010-01-04 02:52:25 +08:00
|
|
|
|
2011-06-10 16:26:05 +08:00
|
|
|
TestRunner = get_runner(settings, options.get('testrunner'))
|
2011-10-23 11:43:43 +08:00
|
|
|
options['verbosity'] = int(options.get('verbosity'))
|
2007-08-16 14:06:55 +08:00
|
|
|
|
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
|
|
|
if options.get('liveserver') is not None:
|
|
|
|
os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = options['liveserver']
|
|
|
|
del options['liveserver']
|
|
|
|
|
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:
|
2010-01-04 02:52:25 +08:00
|
|
|
sys.exit(bool(failures))
|