diff -r 35931243adaa django/test/simple.py
|
a
|
b
|
|
| 208 | 208 | setup_test_environment() |
| 209 | 209 | settings.DEBUG = False |
| 210 | 210 | |
| 211 | | def build_suite(self, test_labels, extra_tests=None): |
| | 211 | def build_suite(self, test_labels, extra_tests=None, exclude_labels=None): |
| 212 | 212 | suite = unittest.TestSuite() |
| 213 | 213 | |
| | 214 | if exclude_labels is None: |
| | 215 | exclude_labels = [] |
| | 216 | |
| 214 | 217 | if test_labels: |
| 215 | 218 | for label in test_labels: |
| | 219 | if label in exclude_labels: |
| | 220 | if self.verbosity >= 1: |
| | 221 | print 'Skipping test %s' % label |
| | 222 | continue |
| 216 | 223 | if '.' in label: |
| 217 | 224 | suite.addTest(build_test(label)) |
| 218 | 225 | else: |
| … |
… |
|
| 250 | 257 | def suite_result(self, result): |
| 251 | 258 | return len(result.failures) + len(result.errors) |
| 252 | 259 | |
| 253 | | def run_tests(self, test_labels, extra_tests=None): |
| | 260 | def run_tests(self, test_labels, extra_tests=None, exclude_labels=None): |
| 254 | 261 | """ |
| 255 | 262 | Run the unit tests for all the test labels in the provided list. |
| 256 | 263 | Labels must be of the form: |
| … |
… |
|
| 267 | 274 | A list of 'extra' tests may also be provided; these tests |
| 268 | 275 | will be added to the test suite. |
| 269 | 276 | |
| | 277 | It's also possible to specify a list of labels to exclude from the |
| | 278 | test suite by using the exclude_labels parameter. |
| | 279 | |
| 270 | 280 | Returns the number of tests that failed. |
| 271 | 281 | """ |
| 272 | 282 | self.setup_test_environment() |
| 273 | 283 | |
| 274 | | suite = self.build_suite(test_labels, extra_tests) |
| | 284 | suite = self.build_suite(test_labels, extra_tests, exclude_labels) |
| 275 | 285 | |
| 276 | 286 | old_names = self.setup_databases() |
| 277 | 287 | |
diff -r 35931243adaa tests/runtests.py
|
a
|
b
|
|
| 86 | 86 | self.assert_(not unexpected, "Unexpected Errors: " + '\n'.join(unexpected)) |
| 87 | 87 | self.assert_(not missing, "Missing Errors: " + '\n'.join(missing)) |
| 88 | 88 | |
| 89 | | def django_tests(verbosity, interactive, failfast, test_labels): |
| | 89 | def django_tests(verbosity, interactive, failfast, test_labels, exclude_labels=None): |
| 90 | 90 | from django.conf import settings |
| 91 | 91 | |
| | 92 | if exclude_labels is None: |
| | 93 | exclude_labels = [] |
| | 94 | |
| 92 | 95 | old_installed_apps = settings.INSTALLED_APPS |
| 93 | 96 | old_root_urlconf = getattr(settings, "ROOT_URLCONF", "") |
| 94 | 97 | old_template_dirs = settings.TEMPLATE_DIRS |
| … |
… |
|
| 123 | 126 | get_apps() |
| 124 | 127 | |
| 125 | 128 | # Load all the test model apps. |
| | 129 | test_labels_set = set([label.split('.')[0] for label in test_labels if label not in exclude_labels]) |
| 126 | 130 | for model_dir, model_name in get_test_models(): |
| 127 | 131 | model_label = '.'.join([model_dir, model_name]) |
| 128 | 132 | try: |
| 129 | 133 | # if the model was named on the command line, or |
| 130 | 134 | # no models were named (i.e., run all), import |
| 131 | 135 | # this model and add it to the list to test. |
| 132 | | if not test_labels or model_name in set([label.split('.')[0] for label in test_labels]): |
| | 136 | # Also, skip the tests explicitely excluded by the user |
| | 137 | if not test_labels or model_name in test_labels_set: |
| | 138 | if model_name in exclude_labels: |
| | 139 | if verbosity >= 1: |
| | 140 | print "Skipping app %s" % model_name |
| | 141 | continue |
| 133 | 142 | if verbosity >= 1: |
| 134 | 143 | print "Importing model %s" % model_name |
| 135 | 144 | mod = load_app(model_label) |
| … |
… |
|
| 153 | 162 | except ValueError: |
| 154 | 163 | pass |
| 155 | 164 | |
| 156 | | # Run the test suite, including the extra validation tests. |
| | 165 | # Run the test suite, including the extra validation tests and skipping |
| | 166 | # the test explicitely excluded. |
| 157 | 167 | from django.test.utils import get_runner |
| 158 | 168 | if not hasattr(settings, 'TEST_RUNNER'): |
| 159 | 169 | settings.TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner' |
| … |
… |
|
| 198 | 208 | help='Tells Django to stop running the test suite after first failed test.') |
| 199 | 209 | parser.add_option('--settings', |
| 200 | 210 | help='Python path to settings module, e.g. "myproject.settings". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.') |
| | 211 | parser.add_option('-e', '--exclude', action='append', dest='exclude', default=[], |
| | 212 | help='Test to exclude (use multiple times to exclude multiple tests).') |
| 201 | 213 | options, args = parser.parse_args() |
| 202 | 214 | if options.settings: |
| 203 | 215 | os.environ['DJANGO_SETTINGS_MODULE'] = options.settings |
| 204 | 216 | elif "DJANGO_SETTINGS_MODULE" not in os.environ: |
| 205 | 217 | parser.error("DJANGO_SETTINGS_MODULE is not set in the environment. " |
| 206 | 218 | "Set it or use --settings.") |
| 207 | | django_tests(int(options.verbosity), options.interactive, options.failfast, args) |
| | 219 | django_tests(int(options.verbosity), options.interactive, options.failfast, args, options.exclude) |