Login

Exclude Apps When Testing

Author:
cronosa
Posted:
September 29, 2010
Language:
Python
Version:
1.2
Tags:
testing tests exclude
Score:
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[0] and not getattr(settings, 'RUN_ALL_TESTS', False):
            tests = []
            for case in suite:
                pkg = case.__class__.__module__.split('.')[0]
                if pkg not in EXCLUDED_APPS:
                    tests.append(case)
            suite._tests = tests 
        return suite
    

More like this

  1. UnitTesting without create/destroy database by crucialfelix 6 years, 3 months ago
  2. Fail Faster: unsafe_test Management Command by majgis 2 years, 9 months ago
  3. Deep package test runner by eternicode 4 years, 2 months ago
  4. A smart trace() command by aparajita 5 years, 11 months ago
  5. Forcing unit test runner to abort after failed test by simonbun 8 years ago

Comments

cronosa (on September 29, 2010):

So to install:

  1. Place this in an app (I put it in a testing app in a file named simple.py)

  2. Add TEST_RUNNER="testing.simple.AdvancedTestSuiteRunner" to settings

  3. Add EXCLUDE_APPS = ('django', 'app2', app3')

#

KingRolo (on April 5, 2011):

Just what I needed - thanks.

(One brief note, the settings for settings.py is TEST_EXCLUDE rather than EXCLUDE_APPS incase anyone else misses that).

Cheers.

#

Please login first before commenting.