1
1
#!/usr/bin/env python
2
+ from argparse import ArgumentParser
2
3
import logging
3
- from optparse import OptionParser
4
4
import os
5
5
import shutil
6
6
import subprocess
@@ -213,7 +213,7 @@ def django_tests(verbosity, interactive, failfast, test_labels):
213
213
214
214
215
215
def bisect_tests (bisection_label , options , test_labels ):
216
- state = setup (int ( options .verbosity ) , test_labels )
216
+ state = setup (options .verbosity , test_labels )
217
217
218
218
test_labels = test_labels or get_installed ()
219
219
@@ -271,7 +271,7 @@ def bisect_tests(bisection_label, options, test_labels):
271
271
272
272
273
273
def paired_tests (paired_test , options , test_labels ):
274
- state = setup (int ( options .verbosity ) , test_labels )
274
+ state = setup (options .verbosity , test_labels )
275
275
276
276
test_labels = test_labels or get_installed ()
277
277
@@ -307,43 +307,39 @@ def paired_tests(paired_test, options, test_labels):
307
307
308
308
309
309
if __name__ == "__main__" :
310
- usage = "%prog [options] [module module module ...]"
311
- parser = OptionParser ( usage = usage )
312
- parser . add_option (
313
- '-v' , '--verbosity' , action = 'store' , dest = 'verbosity' , default = '1' ,
314
- type = 'choice' , choices = [ '0' , '1' , '2' , '3' ],
315
- help = 'Verbosity level; 0=minimal output, 1=normal output , 2=all '
316
- ' output' )
317
- parser .add_option (
310
+ parser = ArgumentParser ( description = "Run the Django test suite." )
311
+ parser . add_argument ( 'modules' , nargs = '*' , metavar = 'module' ,
312
+ help = 'Optional path(s) to test modules; e.g. "i18n" or '
313
+ '"i18n.tests.TranslationTests.test_lazy_objects".' )
314
+ parser . add_argument (
315
+ '-v' , '--verbosity' , default = 1 , type = int , choices = [ 0 , 1 , 2 , 3 ],
316
+ help = 'Verbosity level; 0=minimal output, 1=normal output, 2=all output' )
317
+ parser .add_argument (
318
318
'--noinput' , action = 'store_false' , dest = 'interactive' , default = True ,
319
319
help = 'Tells Django to NOT prompt the user for input of any kind.' )
320
- parser .add_option (
320
+ parser .add_argument (
321
321
'--failfast' , action = 'store_true' , dest = 'failfast' , default = False ,
322
322
help = 'Tells Django to stop running the test suite after first failed '
323
323
'test.' )
324
- parser .add_option (
324
+ parser .add_argument (
325
325
'--settings' ,
326
326
help = 'Python path to settings module, e.g. "myproject.settings". If '
327
- 'this isn\' t provided, the DJANGO_SETTINGS_MODULE environment '
328
- 'variable will be used.' )
329
- parser .add_option (
330
- '--bisect' , action = 'store' , dest = 'bisect' , default = None ,
327
+ 'this isn\' t provided, either the DJANGO_SETTINGS_MODULE '
328
+ 'environment variable or "test_sqlite" will be used.' )
329
+ parser .add_argument ('--bisect' ,
331
330
help = 'Bisect the test suite to discover a test that causes a test '
332
331
'failure when combined with the named test.' )
333
- parser .add_option (
334
- '--pair' , action = 'store' , dest = 'pair' , default = None ,
332
+ parser .add_argument ('--pair' ,
335
333
help = 'Run the test suite in pairs with the named test to find problem '
336
334
'pairs.' )
337
- parser .add_option (
338
- '--liveserver' , action = 'store' , dest = 'liveserver' , default = None ,
335
+ parser .add_argument ('--liveserver' ,
339
336
help = 'Overrides the default address where the live server (used with '
340
337
'LiveServerTestCase) is expected to run from. The default value '
341
338
'is localhost:8081.' )
342
- parser .add_option (
343
- '--selenium' , action = 'store_true' , dest = 'selenium' ,
344
- default = False ,
339
+ parser .add_argument (
340
+ '--selenium' , action = 'store_true' , dest = 'selenium' , default = False ,
345
341
help = 'Run the Selenium tests as well (if Selenium is installed)' )
346
- options , args = parser .parse_args ()
342
+ options = parser .parse_args ()
347
343
if options .settings :
348
344
os .environ ['DJANGO_SETTINGS_MODULE' ] = options .settings
349
345
else :
@@ -358,11 +354,11 @@ def paired_tests(paired_test, options, test_labels):
358
354
os .environ ['DJANGO_SELENIUM_TESTS' ] = '1'
359
355
360
356
if options .bisect :
361
- bisect_tests (options .bisect , options , args )
357
+ bisect_tests (options .bisect , options , options . modules )
362
358
elif options .pair :
363
- paired_tests (options .pair , options , args )
359
+ paired_tests (options .pair , options , options . modules )
364
360
else :
365
- failures = django_tests (int ( options .verbosity ) , options .interactive ,
366
- options .failfast , args )
361
+ failures = django_tests (options .verbosity , options .interactive ,
362
+ options .failfast , options . modules )
367
363
if failures :
368
364
sys .exit (bool (failures ))
0 commit comments