2005-07-29 15:15:40 +00:00
|
|
|
#!/usr/bin/env python
|
2016-02-07 02:24:36 +00:00
|
|
|
import argparse
|
2015-06-04 16:35:18 +00:00
|
|
|
import atexit
|
2015-09-15 18:13:34 +00:00
|
|
|
import copy
|
2011-08-12 08:43:52 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import tempfile
|
2013-06-14 14:02:30 +00:00
|
|
|
import warnings
|
2005-07-29 15:15:40 +00:00
|
|
|
|
2013-12-30 14:42:15 +00:00
|
|
|
import django
|
2014-05-25 21:01:41 +00:00
|
|
|
from django.apps import apps
|
2014-05-24 11:29:23 +00:00
|
|
|
from django.conf import settings
|
2015-09-06 09:12:08 +00:00
|
|
|
from django.db import connection, connections
|
2015-01-28 12:35:27 +00:00
|
|
|
from django.test import TestCase, TransactionTestCase
|
2015-02-05 19:31:02 +00:00
|
|
|
from django.test.runner import default_test_processes
|
2016-02-07 02:24:36 +00:00
|
|
|
from django.test.selenium import SeleniumTestCaseBase
|
2014-05-24 11:29:23 +00:00
|
|
|
from django.test.utils import get_runner
|
2012-07-20 12:48:51 +00:00
|
|
|
from django.utils import six
|
2015-01-28 12:35:27 +00:00
|
|
|
from django.utils._os import upath
|
2016-07-06 18:34:33 +00:00
|
|
|
from django.utils.deprecation import (
|
|
|
|
RemovedInDjango20Warning, RemovedInDjango21Warning,
|
|
|
|
)
|
2015-03-23 22:17:43 +00:00
|
|
|
from django.utils.log import DEFAULT_LOGGING
|
2014-02-26 21:48:20 +00:00
|
|
|
|
2015-10-28 17:24:00 +00:00
|
|
|
# Make deprecation warnings errors to ensure no usage of deprecated features.
|
2014-11-26 21:21:29 +00:00
|
|
|
warnings.simplefilter("error", RemovedInDjango20Warning)
|
2016-07-06 18:34:33 +00:00
|
|
|
warnings.simplefilter("error", RemovedInDjango21Warning)
|
2015-11-13 20:54:05 +00:00
|
|
|
# Make runtime warning errors to ensure no usage of error prone patterns.
|
|
|
|
warnings.simplefilter("error", RuntimeWarning)
|
2015-10-28 17:24:00 +00:00
|
|
|
# Ignore known warnings in test dependencies.
|
|
|
|
warnings.filterwarnings("ignore", "'U' mode is deprecated", DeprecationWarning, module='docutils.io')
|
2014-02-26 21:48:20 +00:00
|
|
|
|
2013-10-22 14:52:04 +00:00
|
|
|
RUNTESTS_DIR = os.path.abspath(os.path.dirname(upath(__file__)))
|
2013-05-11 03:08:45 +00:00
|
|
|
|
2014-12-18 20:54:02 +00:00
|
|
|
TEMPLATE_DIR = os.path.join(RUNTESTS_DIR, 'templates')
|
|
|
|
|
2015-02-21 17:56:36 +00:00
|
|
|
# Create a specific subdirectory for the duration of the test suite.
|
|
|
|
TMPDIR = tempfile.mkdtemp(prefix='django_')
|
|
|
|
# Set the TMPDIR environment variable in addition to tempfile.tempdir
|
|
|
|
# so that children processes inherit it.
|
|
|
|
tempfile.tempdir = os.environ['TMPDIR'] = TMPDIR
|
2005-07-29 22:35:54 +00:00
|
|
|
|
2015-06-04 16:35:18 +00:00
|
|
|
# Removing the temporary TMPDIR. Ensure we pass in unicode so that it will
|
|
|
|
# successfully remove temp trees containing non-ASCII filenames on Windows.
|
|
|
|
# (We're assuming the temp dir name itself only contains ASCII characters.)
|
|
|
|
atexit.register(shutil.rmtree, six.text_type(TMPDIR))
|
|
|
|
|
|
|
|
|
2013-05-11 03:08:45 +00:00
|
|
|
SUBDIRS_TO_SKIP = [
|
2013-07-09 13:17:26 +00:00
|
|
|
'data',
|
2015-02-03 23:02:59 +00:00
|
|
|
'import_error_package',
|
2013-05-11 03:08:45 +00:00
|
|
|
'test_discovery_sample',
|
|
|
|
'test_discovery_sample2',
|
|
|
|
]
|
2010-04-14 18:17:44 +00:00
|
|
|
|
2006-05-26 21:28:12 +00:00
|
|
|
ALWAYS_INSTALLED_APPS = [
|
|
|
|
'django.contrib.contenttypes',
|
2006-06-20 14:27:44 +00:00
|
|
|
'django.contrib.auth',
|
2007-08-15 11:25:22 +00:00
|
|
|
'django.contrib.sites',
|
2006-05-26 21:28:12 +00:00
|
|
|
'django.contrib.sessions',
|
2009-12-09 16:57:23 +00:00
|
|
|
'django.contrib.messages',
|
2014-01-24 21:43:00 +00:00
|
|
|
'django.contrib.admin.apps.SimpleAdminConfig',
|
2010-10-20 01:33:24 +00:00
|
|
|
'django.contrib.staticfiles',
|
2006-05-26 21:28:12 +00:00
|
|
|
]
|
|
|
|
|
2015-11-07 15:12:37 +00:00
|
|
|
ALWAYS_MIDDLEWARE = [
|
2014-04-20 12:58:29 +00:00
|
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
|
|
'django.middleware.common.CommonMiddleware',
|
|
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
2015-01-21 16:55:57 +00:00
|
|
|
]
|
2014-04-20 12:58:29 +00:00
|
|
|
|
2015-02-10 00:20:39 +00:00
|
|
|
# Need to add the associated contrib app to INSTALLED_APPS in some cases to
|
|
|
|
# avoid "RuntimeError: Model class X doesn't declare an explicit app_label
|
2015-12-24 18:28:32 +00:00
|
|
|
# and isn't in an application in INSTALLED_APPS."
|
2015-02-10 00:20:39 +00:00
|
|
|
CONTRIB_TESTS_TO_APPS = {
|
|
|
|
'flatpages_tests': 'django.contrib.flatpages',
|
2015-02-10 13:41:45 +00:00
|
|
|
'redirects_tests': 'django.contrib.redirects',
|
2015-02-10 00:20:39 +00:00
|
|
|
}
|
|
|
|
|
2010-12-21 23:42:12 +00:00
|
|
|
|
2011-01-21 15:55:27 +00:00
|
|
|
def get_test_modules():
|
|
|
|
modules = []
|
2013-07-09 13:58:56 +00:00
|
|
|
discovery_paths = [
|
2013-02-26 08:57:29 +00:00
|
|
|
(None, RUNTESTS_DIR),
|
2015-04-04 16:09:46 +00:00
|
|
|
# GIS tests are in nested apps
|
|
|
|
('gis_tests', os.path.join(RUNTESTS_DIR, 'gis_tests')),
|
2013-07-09 13:58:56 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
for modpath, dirpath in discovery_paths:
|
2006-06-20 14:27:44 +00:00
|
|
|
for f in os.listdir(dirpath):
|
2013-02-26 08:57:29 +00:00
|
|
|
if ('.' in f or
|
2013-11-26 09:43:46 +00:00
|
|
|
os.path.basename(f) in SUBDIRS_TO_SKIP or
|
2014-02-26 16:43:14 +00:00
|
|
|
os.path.isfile(f) or
|
|
|
|
not os.path.exists(os.path.join(dirpath, f, '__init__.py'))):
|
2006-06-20 07:12:45 +00:00
|
|
|
continue
|
2013-05-11 03:08:45 +00:00
|
|
|
modules.append((modpath, f))
|
2011-01-21 15:55:27 +00:00
|
|
|
return modules
|
2005-07-29 22:35:54 +00:00
|
|
|
|
2013-07-09 13:17:26 +00:00
|
|
|
|
2013-05-11 03:08:45 +00:00
|
|
|
def get_installed():
|
2013-12-24 11:25:17 +00:00
|
|
|
return [app_config.name for app_config in apps.get_app_configs()]
|
2013-05-11 03:08:45 +00:00
|
|
|
|
|
|
|
|
2015-02-05 19:31:02 +00:00
|
|
|
def setup(verbosity, test_labels, parallel):
|
2015-02-06 11:32:03 +00:00
|
|
|
if verbosity >= 1:
|
2015-09-06 09:12:08 +00:00
|
|
|
msg = "Testing against Django installed in '%s'" % os.path.dirname(django.__file__)
|
2015-09-12 18:59:31 +00:00
|
|
|
max_parallel = default_test_processes() if parallel == 0 else parallel
|
|
|
|
if max_parallel > 1:
|
|
|
|
msg += " with up to %d processes" % max_parallel
|
2015-09-06 09:12:08 +00:00
|
|
|
print(msg)
|
2013-10-22 14:52:04 +00:00
|
|
|
|
2013-06-04 06:09:29 +00:00
|
|
|
# Force declaring available_apps in TransactionTestCase for faster tests.
|
|
|
|
def no_available_apps(self):
|
|
|
|
raise Exception("Please define available_apps in TransactionTestCase "
|
|
|
|
"and its subclasses.")
|
|
|
|
TransactionTestCase.available_apps = property(no_available_apps)
|
|
|
|
TestCase.available_apps = None
|
|
|
|
|
2010-10-09 14:44:54 +00:00
|
|
|
state = {
|
|
|
|
'INSTALLED_APPS': settings.INSTALLED_APPS,
|
|
|
|
'ROOT_URLCONF': getattr(settings, "ROOT_URLCONF", ""),
|
2014-12-18 20:54:02 +00:00
|
|
|
'TEMPLATES': settings.TEMPLATES,
|
2010-10-09 14:44:54 +00:00
|
|
|
'LANGUAGE_CODE': settings.LANGUAGE_CODE,
|
2011-06-30 09:06:19 +00:00
|
|
|
'STATIC_URL': settings.STATIC_URL,
|
2011-08-12 08:43:52 +00:00
|
|
|
'STATIC_ROOT': settings.STATIC_ROOT,
|
2015-11-07 15:12:37 +00:00
|
|
|
'MIDDLEWARE': settings.MIDDLEWARE,
|
2010-10-09 14:44:54 +00:00
|
|
|
}
|
2006-12-15 06:06:52 +00:00
|
|
|
|
2007-02-10 04:01:19 +00:00
|
|
|
# Redirect some settings for the duration of these tests.
|
2006-08-27 13:59:47 +00:00
|
|
|
settings.INSTALLED_APPS = ALWAYS_INSTALLED_APPS
|
2006-09-02 09:34:40 +00:00
|
|
|
settings.ROOT_URLCONF = 'urls'
|
2011-06-30 09:06:19 +00:00
|
|
|
settings.STATIC_URL = '/static/'
|
2015-02-21 17:56:36 +00:00
|
|
|
settings.STATIC_ROOT = os.path.join(TMPDIR, 'static')
|
2014-12-18 20:54:02 +00:00
|
|
|
settings.TEMPLATES = [{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
|
|
'DIRS': [TEMPLATE_DIR],
|
|
|
|
'APP_DIRS': True,
|
|
|
|
'OPTIONS': {
|
|
|
|
'context_processors': [
|
|
|
|
'django.template.context_processors.debug',
|
2015-01-12 21:31:44 +00:00
|
|
|
'django.template.context_processors.request',
|
|
|
|
'django.contrib.auth.context_processors.auth',
|
2014-12-18 20:54:02 +00:00
|
|
|
'django.contrib.messages.context_processors.messages',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}]
|
2007-10-21 17:26:32 +00:00
|
|
|
settings.LANGUAGE_CODE = 'en'
|
2007-12-01 21:58:51 +00:00
|
|
|
settings.SITE_ID = 1
|
2015-11-07 15:12:37 +00:00
|
|
|
settings.MIDDLEWARE = ALWAYS_MIDDLEWARE
|
2014-06-16 17:28:03 +00:00
|
|
|
settings.MIGRATION_MODULES = {
|
2016-01-25 19:29:24 +00:00
|
|
|
# This lets us skip creating migrations for the test models as many of
|
|
|
|
# them depend on one of the following contrib applications.
|
|
|
|
'auth': None,
|
|
|
|
'contenttypes': None,
|
|
|
|
'sessions': None,
|
2014-06-16 17:28:03 +00:00
|
|
|
}
|
2015-09-15 18:13:34 +00:00
|
|
|
log_config = copy.deepcopy(DEFAULT_LOGGING)
|
2015-03-23 22:17:43 +00:00
|
|
|
# Filter out non-error logging so we don't have to capture it in lots of
|
|
|
|
# tests.
|
|
|
|
log_config['loggers']['django']['level'] = 'ERROR'
|
|
|
|
settings.LOGGING = log_config
|
2006-12-15 06:06:52 +00:00
|
|
|
|
2015-01-29 19:12:08 +00:00
|
|
|
warnings.filterwarnings(
|
|
|
|
'ignore',
|
|
|
|
'The GeoManager class is deprecated.',
|
2015-06-22 17:54:35 +00:00
|
|
|
RemovedInDjango20Warning
|
2015-01-29 19:12:08 +00:00
|
|
|
)
|
2014-07-12 13:50:27 +00:00
|
|
|
|
2006-12-15 06:06:52 +00:00
|
|
|
# Load all the ALWAYS_INSTALLED_APPS.
|
2014-01-01 21:55:50 +00:00
|
|
|
django.setup()
|
2006-12-15 06:06:52 +00:00
|
|
|
|
2007-02-10 04:01:19 +00:00
|
|
|
# Load all the test model apps.
|
2011-01-21 15:55:27 +00:00
|
|
|
test_modules = get_test_modules()
|
2010-12-21 23:42:12 +00:00
|
|
|
|
2013-05-11 03:08:45 +00:00
|
|
|
# Reduce given test labels to just the app module path
|
|
|
|
test_labels_set = set()
|
|
|
|
for label in test_labels:
|
2015-02-10 17:03:47 +00:00
|
|
|
bits = label.split('.')[:1]
|
2013-05-11 03:08:45 +00:00
|
|
|
test_labels_set.add('.'.join(bits))
|
|
|
|
|
2014-05-24 08:53:22 +00:00
|
|
|
installed_app_names = set(get_installed())
|
2013-05-11 03:08:45 +00:00
|
|
|
for modpath, module_name in test_modules:
|
|
|
|
if modpath:
|
|
|
|
module_label = '.'.join([modpath, module_name])
|
2013-02-26 08:57:29 +00:00
|
|
|
else:
|
|
|
|
module_label = module_name
|
2013-05-11 03:08:45 +00:00
|
|
|
# if the module (or an ancestor) was named on the command line, or
|
2011-01-21 15:55:27 +00:00
|
|
|
# no modules were named (i.e., run all), import
|
2013-05-11 03:08:45 +00:00
|
|
|
# this module and add it to INSTALLED_APPS.
|
|
|
|
if not test_labels:
|
|
|
|
module_found_in_labels = True
|
|
|
|
else:
|
2013-12-26 12:46:15 +00:00
|
|
|
module_found_in_labels = any(
|
|
|
|
# exact match or ancestor match
|
|
|
|
module_label == label or module_label.startswith(label + '.')
|
|
|
|
for label in test_labels_set)
|
2013-05-11 03:08:45 +00:00
|
|
|
|
2015-02-10 00:20:39 +00:00
|
|
|
if module_name in CONTRIB_TESTS_TO_APPS and module_found_in_labels:
|
|
|
|
settings.INSTALLED_APPS.append(CONTRIB_TESTS_TO_APPS[module_name])
|
|
|
|
|
2014-01-24 21:43:00 +00:00
|
|
|
if module_found_in_labels and module_label not in installed_app_names:
|
2010-08-20 15:03:11 +00:00
|
|
|
if verbosity >= 2:
|
2012-04-28 16:02:01 +00:00
|
|
|
print("Importing application %s" % module_name)
|
2014-01-24 21:43:00 +00:00
|
|
|
settings.INSTALLED_APPS.append(module_label)
|
2014-05-24 08:53:22 +00:00
|
|
|
|
2015-02-10 15:07:44 +00:00
|
|
|
# Add contrib.gis to INSTALLED_APPS if needed (rather than requiring
|
|
|
|
# @override_settings(INSTALLED_APPS=...) on all test cases.
|
|
|
|
gis = 'django.contrib.gis'
|
|
|
|
if connection.features.gis_enabled and gis not in settings.INSTALLED_APPS:
|
|
|
|
if verbosity >= 2:
|
|
|
|
print("Importing application %s" % gis)
|
|
|
|
settings.INSTALLED_APPS.append(gis)
|
|
|
|
|
2014-05-24 08:53:22 +00:00
|
|
|
apps.set_installed_apps(settings.INSTALLED_APPS)
|
2006-08-27 13:59:47 +00:00
|
|
|
|
2010-10-09 14:44:54 +00:00
|
|
|
return state
|
|
|
|
|
2013-09-19 21:02:49 +00:00
|
|
|
|
2010-10-09 14:44:54 +00:00
|
|
|
def teardown(state):
|
|
|
|
# Restore the old settings.
|
|
|
|
for key, value in state.items():
|
|
|
|
setattr(settings, key, value)
|
|
|
|
|
2013-09-19 21:02:49 +00:00
|
|
|
|
2015-09-06 09:12:08 +00:00
|
|
|
def actual_test_processes(parallel):
|
|
|
|
if parallel == 0:
|
|
|
|
# This doesn't work before django.setup() on some databases.
|
2015-09-12 18:58:26 +00:00
|
|
|
if all(conn.features.can_clone_databases for conn in connections.all()):
|
2015-09-06 09:12:08 +00:00
|
|
|
return default_test_processes()
|
|
|
|
else:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return parallel
|
|
|
|
|
|
|
|
|
2016-02-07 02:24:36 +00:00
|
|
|
class ActionSelenium(argparse.Action):
|
|
|
|
"""
|
|
|
|
Validate the comma-separated list of requested browsers.
|
|
|
|
"""
|
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
|
|
|
browsers = values.split(',')
|
|
|
|
for browser in browsers:
|
|
|
|
try:
|
|
|
|
SeleniumTestCaseBase.import_webdriver(browser)
|
|
|
|
except ImportError:
|
|
|
|
raise argparse.ArgumentError(self, "Selenium browser specification '%s' is not valid." % browser)
|
|
|
|
setattr(namespace, self.dest, browsers)
|
|
|
|
|
|
|
|
|
2015-02-05 19:31:02 +00:00
|
|
|
def django_tests(verbosity, interactive, failfast, keepdb, reverse,
|
2015-11-07 13:57:56 +00:00
|
|
|
test_labels, debug_sql, parallel, tags, exclude_tags):
|
2015-02-05 19:31:02 +00:00
|
|
|
state = setup(verbosity, test_labels, parallel)
|
2006-08-27 13:59:47 +00:00
|
|
|
extra_tests = []
|
2008-10-02 12:57:13 +00:00
|
|
|
|
2006-08-27 13:59:47 +00:00
|
|
|
# Run the test suite, including the extra validation tests.
|
2013-05-11 13:47:40 +00:00
|
|
|
if not hasattr(settings, 'TEST_RUNNER'):
|
|
|
|
settings.TEST_RUNNER = 'django.test.runner.DiscoverRunner'
|
|
|
|
TestRunner = get_runner(settings)
|
2010-01-18 15:11:01 +00:00
|
|
|
|
2013-05-11 13:47:40 +00:00
|
|
|
test_runner = TestRunner(
|
2013-05-11 03:08:45 +00:00
|
|
|
verbosity=verbosity,
|
|
|
|
interactive=interactive,
|
|
|
|
failfast=failfast,
|
2014-11-16 01:01:45 +00:00
|
|
|
keepdb=keepdb,
|
2014-11-22 16:59:05 +00:00
|
|
|
reverse=reverse,
|
2015-01-10 22:52:59 +00:00
|
|
|
debug_sql=debug_sql,
|
2015-09-06 09:12:08 +00:00
|
|
|
parallel=actual_test_processes(parallel),
|
2015-11-07 13:57:56 +00:00
|
|
|
tags=tags,
|
|
|
|
exclude_tags=exclude_tags,
|
2013-05-11 03:08:45 +00:00
|
|
|
)
|
2015-01-18 00:41:46 +00:00
|
|
|
failures = test_runner.run_tests(
|
|
|
|
test_labels or get_installed(),
|
|
|
|
extra_tests=extra_tests,
|
|
|
|
)
|
2010-10-09 14:44:54 +00:00
|
|
|
teardown(state)
|
|
|
|
return failures
|
2006-12-15 06:06:52 +00:00
|
|
|
|
2010-10-09 14:44:54 +00:00
|
|
|
|
2016-02-15 18:53:59 +00:00
|
|
|
def get_subprocess_args(options):
|
|
|
|
subprocess_args = [
|
|
|
|
sys.executable, upath(__file__), '--settings=%s' % options.settings
|
|
|
|
]
|
|
|
|
if options.failfast:
|
|
|
|
subprocess_args.append('--failfast')
|
|
|
|
if options.verbosity:
|
|
|
|
subprocess_args.append('--verbosity=%s' % options.verbosity)
|
|
|
|
if not options.interactive:
|
|
|
|
subprocess_args.append('--noinput')
|
2015-11-07 13:57:56 +00:00
|
|
|
if options.tags:
|
|
|
|
subprocess_args.append('--tag=%s' % options.tags)
|
|
|
|
if options.exclude_tags:
|
|
|
|
subprocess_args.append('--exclude_tag=%s' % options.exclude_tags)
|
2016-02-15 18:53:59 +00:00
|
|
|
return subprocess_args
|
|
|
|
|
|
|
|
|
2016-01-02 06:44:33 +00:00
|
|
|
def bisect_tests(bisection_label, options, test_labels, parallel):
|
|
|
|
state = setup(options.verbosity, test_labels, parallel)
|
2010-10-09 14:44:54 +00:00
|
|
|
|
2013-05-11 03:08:45 +00:00
|
|
|
test_labels = test_labels or get_installed()
|
2010-10-09 14:44:54 +00:00
|
|
|
|
2012-04-28 16:02:01 +00:00
|
|
|
print('***** Bisecting test suite: %s' % ' '.join(test_labels))
|
2010-10-09 14:44:54 +00:00
|
|
|
|
|
|
|
# Make sure the bisection point isn't in the test list
|
|
|
|
# Also remove tests that need to be run in specific combinations
|
|
|
|
for label in [bisection_label, 'model_inheritance_same_model_name']:
|
|
|
|
try:
|
|
|
|
test_labels.remove(label)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
|
2016-02-15 18:53:59 +00:00
|
|
|
subprocess_args = get_subprocess_args(options)
|
2010-10-09 14:44:54 +00:00
|
|
|
|
|
|
|
iteration = 1
|
|
|
|
while len(test_labels) > 1:
|
2013-09-23 21:05:36 +00:00
|
|
|
midpoint = len(test_labels) // 2
|
2010-10-09 14:44:54 +00:00
|
|
|
test_labels_a = test_labels[:midpoint] + [bisection_label]
|
|
|
|
test_labels_b = test_labels[midpoint:] + [bisection_label]
|
2012-04-28 16:02:01 +00:00
|
|
|
print('***** Pass %da: Running the first half of the test suite' % iteration)
|
|
|
|
print('***** Test labels: %s' % ' '.join(test_labels_a))
|
2010-10-09 14:44:54 +00:00
|
|
|
failures_a = subprocess.call(subprocess_args + test_labels_a)
|
|
|
|
|
2012-04-28 16:02:01 +00:00
|
|
|
print('***** Pass %db: Running the second half of the test suite' % iteration)
|
|
|
|
print('***** Test labels: %s' % ' '.join(test_labels_b))
|
|
|
|
print('')
|
2010-10-09 14:44:54 +00:00
|
|
|
failures_b = subprocess.call(subprocess_args + test_labels_b)
|
|
|
|
|
|
|
|
if failures_a and not failures_b:
|
2012-04-28 16:02:01 +00:00
|
|
|
print("***** Problem found in first half. Bisecting again...")
|
2016-07-21 08:28:40 +00:00
|
|
|
iteration += 1
|
2010-10-09 14:44:54 +00:00
|
|
|
test_labels = test_labels_a[:-1]
|
|
|
|
elif failures_b and not failures_a:
|
2012-04-28 16:02:01 +00:00
|
|
|
print("***** Problem found in second half. Bisecting again...")
|
2016-07-21 08:28:40 +00:00
|
|
|
iteration += 1
|
2010-10-09 14:44:54 +00:00
|
|
|
test_labels = test_labels_b[:-1]
|
|
|
|
elif failures_a and failures_b:
|
2012-04-28 16:02:01 +00:00
|
|
|
print("***** Multiple sources of failure found")
|
2010-10-09 14:44:54 +00:00
|
|
|
break
|
|
|
|
else:
|
2012-04-28 16:02:01 +00:00
|
|
|
print("***** No source of failure found... try pair execution (--pair)")
|
2010-10-09 14:44:54 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
if len(test_labels) == 1:
|
2012-04-28 16:02:01 +00:00
|
|
|
print("***** Source of error: %s" % test_labels[0])
|
2010-10-09 14:44:54 +00:00
|
|
|
teardown(state)
|
|
|
|
|
2013-09-19 21:02:49 +00:00
|
|
|
|
2016-01-02 06:44:33 +00:00
|
|
|
def paired_tests(paired_test, options, test_labels, parallel):
|
|
|
|
state = setup(options.verbosity, test_labels, parallel)
|
2010-10-09 14:44:54 +00:00
|
|
|
|
2013-05-11 03:08:45 +00:00
|
|
|
test_labels = test_labels or get_installed()
|
2010-10-09 14:44:54 +00:00
|
|
|
|
2012-04-28 16:02:01 +00:00
|
|
|
print('***** Trying paired execution')
|
2010-10-09 14:44:54 +00:00
|
|
|
|
2010-10-11 12:55:17 +00:00
|
|
|
# Make sure the constant member of the pair isn't in the test list
|
2010-10-09 14:44:54 +00:00
|
|
|
# Also remove tests that need to be run in specific combinations
|
|
|
|
for label in [paired_test, 'model_inheritance_same_model_name']:
|
|
|
|
try:
|
|
|
|
test_labels.remove(label)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
|
2016-02-15 18:53:59 +00:00
|
|
|
subprocess_args = get_subprocess_args(options)
|
2010-10-09 14:44:54 +00:00
|
|
|
|
|
|
|
for i, label in enumerate(test_labels):
|
2012-04-28 16:02:01 +00:00
|
|
|
print('***** %d of %d: Check test pairing with %s' % (
|
|
|
|
i + 1, len(test_labels), label))
|
2010-10-09 14:44:54 +00:00
|
|
|
failures = subprocess.call(subprocess_args + [label, paired_test])
|
|
|
|
if failures:
|
2012-04-28 16:02:01 +00:00
|
|
|
print('***** Found problem pair with %s' % label)
|
2010-10-09 14:44:54 +00:00
|
|
|
return
|
|
|
|
|
2012-04-28 16:02:01 +00:00
|
|
|
print('***** No problem pair found')
|
2010-10-09 14:44:54 +00:00
|
|
|
teardown(state)
|
2006-12-15 06:06:52 +00:00
|
|
|
|
2013-09-19 21:02:49 +00:00
|
|
|
|
2005-07-29 15:15:40 +00:00
|
|
|
if __name__ == "__main__":
|
2016-02-07 02:24:36 +00:00
|
|
|
parser = argparse.ArgumentParser(description="Run the Django test suite.")
|
2016-04-08 02:04:45 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'modules', nargs='*', metavar='module',
|
2014-06-06 19:12:18 +00:00
|
|
|
help='Optional path(s) to test modules; e.g. "i18n" or '
|
2016-04-08 02:04:45 +00:00
|
|
|
'"i18n.tests.TranslationTests.test_lazy_objects".',
|
|
|
|
)
|
2014-06-06 19:12:18 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'-v', '--verbosity', default=1, type=int, choices=[0, 1, 2, 3],
|
2016-04-08 02:04:45 +00:00
|
|
|
help='Verbosity level; 0=minimal output, 1=normal output, 2=all output',
|
|
|
|
)
|
2014-06-06 19:12:18 +00:00
|
|
|
parser.add_argument(
|
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 08:33:58 +00:00
|
|
|
'--noinput', action='store_false', dest='interactive', default=True,
|
2016-04-08 02:04:45 +00:00
|
|
|
help='Tells Django to NOT prompt the user for input of any kind.',
|
|
|
|
)
|
2014-06-06 19:12:18 +00:00
|
|
|
parser.add_argument(
|
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 08:33:58 +00:00
|
|
|
'--failfast', action='store_true', dest='failfast', default=False,
|
2016-04-08 02:04:45 +00:00
|
|
|
help='Tells Django to stop running the test suite after first failed test.',
|
|
|
|
)
|
2014-11-16 01:01:45 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'-k', '--keepdb', action='store_true', dest='keepdb', default=False,
|
2016-04-08 02:04:45 +00:00
|
|
|
help='Tells Django to preserve the test database between runs.',
|
|
|
|
)
|
2014-06-06 19:12:18 +00:00
|
|
|
parser.add_argument(
|
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 08:33:58 +00:00
|
|
|
'--settings',
|
|
|
|
help='Python path to settings module, e.g. "myproject.settings". If '
|
2014-06-06 19:12:18 +00:00
|
|
|
'this isn\'t provided, either the DJANGO_SETTINGS_MODULE '
|
2016-04-08 02:04:45 +00:00
|
|
|
'environment variable or "test_sqlite" will be used.',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--bisect',
|
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 08:33:58 +00:00
|
|
|
help='Bisect the test suite to discover a test that causes a test '
|
2016-04-08 02:04:45 +00:00
|
|
|
'failure when combined with the named test.',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--pair',
|
|
|
|
help='Run the test suite in pairs with the named test to find problem pairs.',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--reverse', action='store_true', default=False,
|
2014-11-22 16:59:05 +00:00
|
|
|
help='Sort test suites and test cases in opposite order to debug '
|
2016-04-08 02:04:45 +00:00
|
|
|
'test side effects not apparent with normal execution lineup.',
|
|
|
|
)
|
2014-06-06 19:12:18 +00:00
|
|
|
parser.add_argument(
|
2016-02-07 02:24:36 +00:00
|
|
|
'--selenium', dest='selenium', action=ActionSelenium, metavar='BROWSERS',
|
2016-04-08 02:04:45 +00:00
|
|
|
help='A comma-separated list of browsers to run the Selenium tests against.',
|
|
|
|
)
|
2015-01-10 22:52:59 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--debug-sql', action='store_true', dest='debug_sql', default=False,
|
2016-04-08 02:04:45 +00:00
|
|
|
help='Turn on the SQL query logger within tests.',
|
|
|
|
)
|
2015-02-05 19:31:02 +00:00
|
|
|
parser.add_argument(
|
2015-09-06 09:12:08 +00:00
|
|
|
'--parallel', dest='parallel', nargs='?', default=0, type=int,
|
2015-11-27 17:44:11 +00:00
|
|
|
const=default_test_processes(), metavar='N',
|
2016-04-08 02:04:45 +00:00
|
|
|
help='Run tests using up to N parallel processes.',
|
|
|
|
)
|
2015-11-07 13:57:56 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--tag', dest='tags', action='append',
|
2016-04-08 02:04:45 +00:00
|
|
|
help='Run only tests with the specified tags. Can be used multiple times.',
|
|
|
|
)
|
2015-11-07 13:57:56 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--exclude-tag', dest='exclude_tags', action='append',
|
2016-04-08 02:04:45 +00:00
|
|
|
help='Do not run tests with the specified tag. Can be used multiple times.',
|
|
|
|
)
|
2015-02-05 19:31:02 +00:00
|
|
|
|
2014-06-06 19:12:18 +00:00
|
|
|
options = parser.parse_args()
|
2014-06-11 15:07:33 +00:00
|
|
|
|
2014-11-29 16:45:06 +00:00
|
|
|
# mock is a required dependency
|
|
|
|
try:
|
|
|
|
from django.test import mock # NOQA
|
|
|
|
except ImportError:
|
|
|
|
print(
|
|
|
|
"Please install test dependencies first: \n"
|
|
|
|
"$ pip install -r requirements/py%s.txt" % sys.version_info.major
|
|
|
|
)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2014-06-11 15:07:33 +00:00
|
|
|
# Allow including a trailing slash on app_labels for tab completion convenience
|
|
|
|
options.modules = [os.path.normpath(labels) for labels in options.modules]
|
|
|
|
|
2005-08-10 15:36:16 +00:00
|
|
|
if options.settings:
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
|
2011-01-27 00:00:20 +00:00
|
|
|
else:
|
2013-02-28 08:00:38 +00:00
|
|
|
if "DJANGO_SETTINGS_MODULE" not in os.environ:
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'test_sqlite'
|
2011-01-27 00:00:20 +00:00
|
|
|
options.settings = os.environ['DJANGO_SETTINGS_MODULE']
|
2010-10-09 14:44:54 +00:00
|
|
|
|
2013-02-25 17:14:42 +00:00
|
|
|
if options.selenium:
|
2016-02-19 18:56:13 +00:00
|
|
|
if not options.tags:
|
|
|
|
options.tags = ['selenium']
|
|
|
|
elif 'selenium' not in options.tags:
|
|
|
|
options.tags.append('selenium')
|
2016-02-07 02:24:36 +00:00
|
|
|
SeleniumTestCaseBase.browsers = options.selenium
|
2013-02-23 16:10:48 +00:00
|
|
|
|
2010-10-09 14:44:54 +00:00
|
|
|
if options.bisect:
|
2016-01-02 06:44:33 +00:00
|
|
|
bisect_tests(options.bisect, options, options.modules, options.parallel)
|
2010-10-09 14:44:54 +00:00
|
|
|
elif options.pair:
|
2016-01-02 06:44:33 +00:00
|
|
|
paired_tests(options.pair, options, options.modules, options.parallel)
|
2010-10-09 14:44:54 +00:00
|
|
|
else:
|
2015-11-07 13:57:56 +00:00
|
|
|
failures = django_tests(
|
|
|
|
options.verbosity, options.interactive, options.failfast,
|
|
|
|
options.keepdb, options.reverse, options.modules,
|
|
|
|
options.debug_sql, options.parallel, options.tags,
|
|
|
|
options.exclude_tags,
|
|
|
|
)
|
2010-10-09 14:44:54 +00:00
|
|
|
if failures:
|
2016-11-03 11:40:59 +00:00
|
|
|
sys.exit(1)
|