Exclude Apps When Testing

 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 5 years, 2 months ago
  2. Fail Faster: unsafe_test Management Command by majgis 1 year, 8 months ago
  3. Deep package test runner by eternicode 3 years, 1 month ago
  4. A smart trace() command by aparajita 4 years, 10 months ago
  5. post_migrate handler to load initial SQL after migrating with south by stingydrone 3 years, 3 months 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.

#

(Forgotten your password?)