Browse files

Fixed #3771 -- Modified the test runner to observe the --noinput arg…

…ument controlling script interactivity. This means that test scripts can now be put in a buildbot environment. This is a backwards incompatible change for anyone that has written a custom test runner. Thanks for the suggestion,

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
freakboy3742 committed Jul 23, 2007
1 parent 3043816 commit 1b7fe09660e640bd3cdbf55d340b702d951dd22e
Showing with 24 additions and 11 deletions.
  1. +9 −4 django/core/
  2. +2 −2 django/test/
  3. +8 −2 docs/testing.txt
  4. +5 −3 tests/
@@ -1331,7 +1331,7 @@ def runfcgi(args):
runfcgi.args = '[various KEY=val options, use `runfcgi help` for help]'
-def test(app_labels, verbosity=1):
+def test(app_labels, verbosity=1, interactive=True):
"Runs the test suite for the specified applications"
from django.conf import settings
from django.db.models import get_app, get_apps
@@ -1350,12 +1350,12 @@ def test(app_labels, verbosity=1):
test_module = __import__(test_module_name, {}, {}, test_path[-1])
test_runner = getattr(test_module, test_path[-1])
- failures = test_runner(app_list, verbosity)
+ failures = test_runner(app_list, verbosity=verbosity, interactive=interactive)
if failures:
test.help_doc = 'Runs the test suite for the specified applications, or the entire site if no apps are specified'
-test.args = '[--verbosity] ' + APP_ARGS
+test.args = '[--verbosity] [--noinput]' + APP_ARGS
def load_data(fixture_labels, verbosity=1):
"Installs the provided fixture file(s) as data in the database."
@@ -1631,7 +1631,12 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
except IndexError:
- elif action in ('test', 'loaddata'):
+ elif action == 'test':
+ try:
+ action_mapping[action](args[1:], int(options.verbosity), options.interactive)
+ except IndexError:
+ parser.print_usage_and_exit()
+ elif action == 'loaddata':
action_mapping[action](args[1:], int(options.verbosity))
except IndexError:
@@ -69,7 +69,7 @@ def build_suite(app_module):
return suite
-def run_tests(module_list, verbosity=1, extra_tests=[]):
+def run_tests(module_list, verbosity=1, interactive=True, extra_tests=[]):
Run the unit tests for all the modules in the provided list.
This testrunner will search each of the modules in the provided list,
@@ -91,7 +91,7 @@ def run_tests(module_list, verbosity=1, extra_tests=[]):
old_name = settings.DATABASE_NAME
- create_test_db(verbosity)
+ create_test_db(verbosity, autoclobber=not interactive)
result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
destroy_test_db(old_name, verbosity)
@@ -662,17 +662,23 @@ framework that can be executed from Python code.
Defining a test runner
By convention, a test runner should be called ``run_tests``; however, you
-can call it anything you want. The only requirement is that it accept two
+can call it anything you want. The only requirement is that it accept three
-``run_tests(module_list, verbosity=1)``
+``run_tests(module_list, verbosity=1, interactive=True)``
The module list is the list of Python modules that contain the models to be
tested. This is the same format returned by ``django.db.models.get_apps()``
Verbosity determines the amount of notification and debug information that
will be printed to the console; ``0`` is no output, ``1`` is normal output,
and ``2`` is verbose output.
+ **New in Django development version** If ``interactive`` is ``True``, the
+ test suite may ask the user for instructions when the test suite is
+ executed. An example of this behavior would be asking for permission to
+ delete an existing test database. If ``interactive`` is ``False, the
+ test suite must be able to run without any manual intervention.
This method should return the number of tests that failed.
Testing utilities
@@ -73,7 +73,7 @@ def runTest(self):
self.assert_(not unexpected, "Unexpected Errors: " + '\n'.join(unexpected))
self.assert_(not missing, "Missing Errors: " + '\n'.join(missing))
-def django_tests(verbosity, tests_to_run):
+def django_tests(verbosity, interactive, tests_to_run):
from django.conf import settings
old_installed_apps = settings.INSTALLED_APPS
@@ -130,7 +130,7 @@ def django_tests(verbosity, tests_to_run):
# Run the test suite, including the extra validation tests.
from django.test.simple import run_tests
- failures = run_tests(test_models, verbosity, extra_tests=extra_tests)
+ failures = run_tests(test_models, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests)
if failures:
@@ -149,6 +149,8 @@ def django_tests(verbosity, tests_to_run):
parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='0',
type='choice', choices=['0', '1', '2'],
help='Verbosity level; 0=minimal output, 1=normal output, 2=all output')
+ parser.add_option('--noinput', action='store_false', dest='interactive', default=True,
+ help='Tells Django to NOT prompt the user for input of any kind.')
help='Python path to settings module, e.g. "myproject.settings". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.')
options, args = parser.parse_args()
@@ -157,4 +159,4 @@ def django_tests(verbosity, tests_to_run):
elif "DJANGO_SETTINGS_MODULE" not in os.environ:
parser.error("DJANGO_SETTINGS_MODULE is not set in the environment. "
"Set it or use --settings.")
- django_tests(int(options.verbosity), args)
+ django_tests(int(options.verbosity), options.interactive, args)

0 comments on commit 1b7fe09

Please sign in to comment.