Skip to content

Instantly share code, notes, and snippets.

@jangxyz
Created February 15, 2013 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jangxyz/4962222 to your computer and use it in GitHub Desktop.
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.
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