Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…ment 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, moof@metamoof.net.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5752 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1b7fe09660e640bd3cdbf55d340b702d951dd22e 1 parent 3043816
Russell Keith-Magee authored July 23, 2007
13  django/core/management.py
@@ -1331,7 +1331,7 @@ def runfcgi(args):
1331 1331
     runfastcgi(args)
1332 1332
 runfcgi.args = '[various KEY=val options, use `runfcgi help` for help]'
1333 1333
 
1334  
-def test(app_labels, verbosity=1):
  1334
+def test(app_labels, verbosity=1, interactive=True):
1335 1335
     "Runs the test suite for the specified applications"
1336 1336
     from django.conf import settings
1337 1337
     from django.db.models import get_app, get_apps
@@ -1350,12 +1350,12 @@ def test(app_labels, verbosity=1):
1350 1350
     test_module = __import__(test_module_name, {}, {}, test_path[-1])
1351 1351
     test_runner = getattr(test_module, test_path[-1])
1352 1352
 
1353  
-    failures = test_runner(app_list, verbosity)
  1353
+    failures = test_runner(app_list, verbosity=verbosity, interactive=interactive)
1354 1354
     if failures:
1355 1355
         sys.exit(failures)
1356 1356
 
1357 1357
 test.help_doc = 'Runs the test suite for the specified applications, or the entire site if no apps are specified'
1358  
-test.args = '[--verbosity] ' + APP_ARGS
  1358
+test.args = '[--verbosity] [--noinput]' + APP_ARGS
1359 1359
 
1360 1360
 def load_data(fixture_labels, verbosity=1):
1361 1361
     "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):
1631 1631
             action_mapping[action](args[1])
1632 1632
         except IndexError:
1633 1633
             parser.print_usage_and_exit()
1634  
-    elif action in ('test', 'loaddata'):
  1634
+    elif action == 'test':
  1635
+        try:
  1636
+            action_mapping[action](args[1:], int(options.verbosity), options.interactive)
  1637
+        except IndexError:
  1638
+            parser.print_usage_and_exit()
  1639
+    elif action == 'loaddata':
1635 1640
         try:
1636 1641
             action_mapping[action](args[1:], int(options.verbosity))
1637 1642
         except IndexError:
4  django/test/simple.py
@@ -69,7 +69,7 @@ def build_suite(app_module):
69 69
             
70 70
     return suite
71 71
 
72  
-def run_tests(module_list, verbosity=1, extra_tests=[]):
  72
+def run_tests(module_list, verbosity=1, interactive=True, extra_tests=[]):
73 73
     """
74 74
     Run the unit tests for all the modules in the provided list.
75 75
     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=[]):
91 91
         suite.addTest(test)
92 92
 
93 93
     old_name = settings.DATABASE_NAME
94  
-    create_test_db(verbosity)
  94
+    create_test_db(verbosity, autoclobber=not interactive)
95 95
     result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
96 96
     destroy_test_db(old_name, verbosity)
97 97
     
10  docs/testing.txt
@@ -662,10 +662,10 @@ framework that can be executed from Python code.
662 662
 Defining a test runner
663 663
 ----------------------
664 664
 By convention, a test runner should be called ``run_tests``; however, you
665  
-can call it anything you want. The only requirement is that it accept two
  665
+can call it anything you want. The only requirement is that it accept three
666 666
 arguments:
667 667
 
668  
-``run_tests(module_list, verbosity=1)``
  668
+``run_tests(module_list, verbosity=1, interactive=True)``
669 669
     The module list is the list of Python modules that contain the models to be
670 670
     tested. This is the same format returned by ``django.db.models.get_apps()``
671 671
 
@@ -673,6 +673,12 @@ arguments:
673 673
     will be printed to the console; ``0`` is no output, ``1`` is normal output,
674 674
     and ``2`` is verbose output.
675 675
 
  676
+    **New in Django development version** If ``interactive`` is ``True``, the
  677
+    test suite may ask the user for instructions when the test suite is
  678
+    executed. An example of this behavior would be asking for permission to
  679
+    delete an existing test database. If ``interactive`` is ``False, the 
  680
+    test suite must be able to run without any manual intervention.
  681
+    
676 682
     This method should return the number of tests that failed.
677 683
 
678 684
 Testing utilities
8  tests/runtests.py
@@ -73,7 +73,7 @@ def runTest(self):
73 73
         self.assert_(not unexpected, "Unexpected Errors: " + '\n'.join(unexpected))
74 74
         self.assert_(not missing, "Missing Errors: " + '\n'.join(missing))
75 75
 
76  
-def django_tests(verbosity, tests_to_run):
  76
+def django_tests(verbosity, interactive, tests_to_run):
77 77
     from django.conf import settings
78 78
 
79 79
     old_installed_apps = settings.INSTALLED_APPS
@@ -130,7 +130,7 @@ def django_tests(verbosity, tests_to_run):
130 130
 
131 131
     # Run the test suite, including the extra validation tests.
132 132
     from django.test.simple import run_tests
133  
-    failures = run_tests(test_models, verbosity, extra_tests=extra_tests)
  133
+    failures = run_tests(test_models, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests)
134 134
     if failures:
135 135
         sys.exit(failures)
136 136
 
@@ -149,6 +149,8 @@ def django_tests(verbosity, tests_to_run):
149 149
     parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='0',
150 150
         type='choice', choices=['0', '1', '2'],
151 151
         help='Verbosity level; 0=minimal output, 1=normal output, 2=all output')
  152
+    parser.add_option('--noinput', action='store_false', dest='interactive', default=True,
  153
+        help='Tells Django to NOT prompt the user for input of any kind.')
152 154
     parser.add_option('--settings',
153 155
         help='Python path to settings module, e.g. "myproject.settings". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.')
154 156
     options, args = parser.parse_args()
@@ -157,4 +159,4 @@ def django_tests(verbosity, tests_to_run):
157 159
     elif "DJANGO_SETTINGS_MODULE" not in os.environ:
158 160
         parser.error("DJANGO_SETTINGS_MODULE is not set in the environment. "
159 161
                       "Set it or use --settings.")
160  
-    django_tests(int(options.verbosity), args)
  162
+    django_tests(int(options.verbosity), options.interactive, args)

0 notes on commit 1b7fe09

Please sign in to comment.
Something went wrong with that request. Please try again.