Created
February 15, 2013 18:13
-
-
Save jangxyz/4962222 to your computer and use it in GitHub Desktop.
Subclass of DjangoTestSuiteRunner, to run every test cases from a module with Django.
I think this is more pythonic than Django's.
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 django.test.simple as dj_test | |
from django.test.simple import unittest | |
class ModuleTestSuiteRunner(dj_test.DjangoTestSuiteRunner): | |
def build_suite(self, test_labels, extra_tests=None, **kwargs): | |
suite = unittest.TestSuite() | |
if test_labels: | |
for label in test_labels: | |
if '.' in label: | |
#suite.addTest(build_test(label)) | |
try: | |
suite.addTest(dj_test.build_test(label)) | |
except ValueError: | |
head, tail = label.split('.', 1) | |
full_label = '.'.join([head, dj_test.TEST_MODULE, tail]) | |
tests = unittest.defaultTestLoader.loadTestsFromName(full_label) | |
suite.addTests(tests) | |
else: | |
app = dj_test.get_app(label) | |
suite.addTest(dj_test.build_suite(app)) | |
else: | |
for app in dj_test.get_apps(): | |
suite.addTest(dj_test.build_suite(app)) | |
if extra_tests: | |
for test in extra_tests: | |
suite.addTest(test) | |
return dj_test.reorder_suite(suite, (dj_test.TestCase,)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment