- September 29, 2010
- tests exclude testing
- 3 (after 3 ratings)
This allows you to exclude certain apps when doing standard tests (manage.py test) by default. You set the settings/local_settings variable EXCLUDE_APPS and it will exclude those apps (like django, registration, south... etc). This makes running tests much faster and you don't have to wait for a bunch of tests you don't care about (per say).
You can override it by adding the app to the command line still. So if 'south' is in the excluded apps you can still run:
'python manage.py test south'
and it will run the south tests.
You will also need to tell django to use this as the test runner: TEST_RUNNER = 'testing.simple.AdvancedTestSuiteRunner'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
from django.test.simple import DjangoTestSuiteRunner #@UnresolvedImport import logging from django.conf import settings EXCLUDED_APPS = getattr(settings, 'TEST_EXCLUDE', ) class AdvancedTestSuiteRunner(DjangoTestSuiteRunner): def __init__(self, *args, **kwargs): from django.conf import settings settings.TESTING = True south_log = logging.getLogger("south") south_log.setLevel(logging.WARNING) super(AdvancedTestSuiteRunner, self).__init__(*args, **kwargs) def build_suite(self, *args, **kwargs): suite = super(AdvancedTestSuiteRunner, self).build_suite(*args, **kwargs) if not args and not getattr(settings, 'RUN_ALL_TESTS', False): tests =  for case in suite: pkg = case.__class__.__module__.split('.') if pkg not in EXCLUDED_APPS: tests.append(case) suite._tests = tests return suite