Last active
December 20, 2015 03:09
-
-
Save qnub/6061487 to your computer and use it in GitHub Desktop.
Run only PROJECT_APPS tests. INSTALLED_APPS += PROJECT_APPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from django.test.simple import DjangoTestSuiteRunner | |
from django.conf import settings | |
TESTING_APPS = getattr(settings, 'PROJECT_APPS', getattr(settings, 'INSTALLED_APPS', [])) | |
class ProjectAppsTestSuiteRunner(DjangoTestSuiteRunner): | |
''' | |
Run only internal project's apps tests. | |
In django settings set: | |
TEST_RUNNER = 'test_runner.ProjectAppsTestSuiteRunner' | |
''' | |
def __init__(self, *args, **kwargs): | |
settings.TESTING = True | |
south_log = logging.getLogger("south") | |
south_log.setLevel(logging.WARNING) | |
super(ProjectAppsTestSuiteRunner, self).__init__(*args, **kwargs) | |
def build_suite(self, *args, **kwargs): | |
suite = super(ProjectAppsTestSuiteRunner, 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 in TESTING_APPS: | |
tests.append(case) | |
suite._tests = tests | |
return suite |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment