diff -r 93cbbb7609e6 django/test/simple.py
a
|
b
|
|
99 | 99 | else: # label is app.TestClass.test_method |
100 | 100 | return TestClass(parts[2]) |
101 | 101 | |
102 | | def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]): |
| 102 | def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], all_excluded=False): |
103 | 103 | """ |
104 | 104 | Run the unit tests for all the test labels in the provided list. |
105 | 105 | Labels must be of the form: |
… |
… |
|
122 | 122 | |
123 | 123 | settings.DEBUG = False |
124 | 124 | suite = unittest.TestSuite() |
125 | | |
126 | | if test_labels: |
| 125 | |
| 126 | if all_excluded: |
| 127 | tmp = [model[1:] for model in test_labels] |
| 128 | test_labels = set(tmp) |
| 129 | |
| 130 | if test_labels and not all_excluded: |
127 | 131 | for label in test_labels: |
128 | 132 | if '.' in label: |
129 | 133 | suite.addTest(build_test(label)) |
130 | 134 | else: |
131 | 135 | app = get_app(label) |
132 | 136 | suite.addTest(build_suite(app)) |
| 137 | elif all_excluded: |
| 138 | for app in get_apps(): |
| 139 | if app.__name__.split('.')[-2] in test_labels: |
| 140 | print 'skipping %s' % app.__name__ |
| 141 | continue |
| 142 | suite.addTest(build_suite(app)) |
133 | 143 | else: |
134 | 144 | for app in get_apps(): |
135 | 145 | suite.addTest(build_suite(app)) |
diff -r 93cbbb7609e6 tests/runtests.py
a
|
b
|
|
117 | 117 | from django.db.models.loading import get_apps, load_app |
118 | 118 | get_apps() |
119 | 119 | |
| 120 | if not test_labels: |
| 121 | all_excluded = False |
| 122 | else: |
| 123 | all_excluded = True |
| 124 | for tl in test_labels: |
| 125 | if tl[0] != '-': |
| 126 | all_excluded = False |
| 127 | |
120 | 128 | # Load all the test model apps. |
| 129 | test_label_set = set([label.split('.')[0] for label in test_labels]) |
121 | 130 | for model_dir, model_name in get_test_models(): |
122 | 131 | model_label = '.'.join([model_dir, model_name]) |
123 | 132 | try: |
124 | 133 | # if the model was named on the command line, or |
125 | 134 | # no models were named (i.e., run all), import |
126 | 135 | # this model and add it to the list to test. |
127 | | if not test_labels or model_name in set([label.split('.')[0] for label in test_labels]): |
| 136 | if not test_labels or all_excluded or model_name in test_label_set: |
128 | 137 | if verbosity >= 1: |
129 | 138 | print "Importing model %s" % model_name |
130 | 139 | mod = load_app(model_label) |
… |
… |
|
150 | 159 | |
151 | 160 | # Run the test suite, including the extra validation tests. |
152 | 161 | from django.test.simple import run_tests |
153 | | failures = run_tests(test_labels, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests) |
| 162 | failures = run_tests(test_labels, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests, all_excluded=all_excluded) |
154 | 163 | if failures: |
155 | 164 | sys.exit(failures) |
156 | 165 | |