diff --git a/django/core/management/commands/test.py b/django/core/management/commands/test.py
index 8ebf3da..b57a2f0 100644
|
a
|
b
|
class Command(BaseCommand):
|
| 6 | 6 | option_list = BaseCommand.option_list + ( |
| 7 | 7 | make_option('--noinput', action='store_false', dest='interactive', default=True, |
| 8 | 8 | help='Tells Django to NOT prompt the user for input of any kind.'), |
| | 9 | make_option('--coverage', action='store_true', dest='coverage', default=False, |
| | 10 | help='Tells Django to run coverage analysis on your test modules.'), |
| 9 | 11 | ) |
| 10 | 12 | help = 'Runs the test suite for the specified applications, or the entire site if no apps are specified.' |
| 11 | 13 | args = '[appname ...]' |
| … |
… |
class Command(BaseCommand):
|
| 18 | 20 | |
| 19 | 21 | verbosity = int(options.get('verbosity', 1)) |
| 20 | 22 | interactive = options.get('interactive', True) |
| | 23 | use_coverage = options.get('coverage', False) |
| 21 | 24 | test_runner = get_runner(settings) |
| 22 | 25 | |
| | 26 | |
| | 27 | if use_coverage: |
| | 28 | try: |
| | 29 | import coverage |
| | 30 | if verbosity > 1: |
| | 31 | print "Running test runner with coverage." |
| | 32 | #coverage.use_cache(0) |
| | 33 | coverage.start() |
| | 34 | except: |
| | 35 | if verbosity > 0: |
| | 36 | print "coverage.py module is not available." |
| | 37 | use_coverage = False |
| | 38 | |
| 23 | 39 | failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive) |
| | 40 | |
| 24 | 41 | if failures: |
| 25 | 42 | sys.exit(failures) |
| | 43 | |
| | 44 | #We only want coverage when our tests are passing. |
| | 45 | if use_coverage: |
| | 46 | coverage.stop() |
| | 47 | coverage_models = [] |
| | 48 | if test_labels: |
| | 49 | for label in test_labels: |
| | 50 | if '.' in label: |
| | 51 | #Test the app, don't know if we really want coverage here. |
| | 52 | label = label.split('.')[0] |
| | 53 | coverage_models.append(__import__(label, globals(), locals(), [''])) |
| | 54 | else: |
| | 55 | from django.db.models.loading import get_apps |
| | 56 | for app in get_apps(): |
| | 57 | if app.__name__.find('django.contrib') == -1: |
| | 58 | coverage_models.append(app) |
| | 59 | |
| | 60 | |
| | 61 | print '---------------------------------------------------------------' |
| | 62 | print ' Unit Test Code Coverage Results' |
| | 63 | print '---------------------------------------------------------------' |
| | 64 | |
| | 65 | coverage.report(coverage_models, show_missing=1) |
| | 66 | |
| | 67 | print '---------------------------------------------------------------' |