Created
March 3, 2011 15:07
-
-
Save mattjmorrison/852891 to your computer and use it in GitHub Desktop.
Django unit test runner that does not setup the database
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
from django.core.management.base import BaseCommand | |
from optparse import make_option | |
import sys | |
from django.test.simple import DjangoTestSuiteRunner | |
class UnitTestSuiteRunner(DjangoTestSuiteRunner): | |
def run_tests(self, test_labels, extra_tests=None, **kwargs): | |
suite = self.build_suite(test_labels, extra_tests) | |
result = self.run_suite(suite) | |
return self.suite_result(suite, result) | |
class Command(BaseCommand): | |
option_list = BaseCommand.option_list + ( | |
make_option('--noinput', action='store_false', dest='interactive', | |
default=True, help='Tells Django to NOT prompt the user for input of any kind.'), | |
make_option('--failfast', action='store_true', dest='failfast', default=False, | |
help='Tells Django to stop running the test suite after first failed test.') | |
) | |
help = 'Runs the test suite for the specified applications, or the entire site if no' | |
help += 'apps are specified.' | |
args = '[appname ...]' | |
def handle(self, *test_labels, **options): | |
verbosity = int(options.get('verbosity', 1)) | |
interactive = options.get('interactive', True) | |
failfast = options.get('failfast', False) | |
test_runner = UnitTestSuiteRunner(verbosity=verbosity, interactive=interactive, | |
failfast=failfast) | |
failures = test_runner.run_tests(test_labels) | |
if failures: | |
sys.exit(bool(failures)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment