Created
March 30, 2012 15:05
-
-
Save mattdeboard/2252156 to your computer and use it in GitHub Desktop.
Django test runner
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.conf import settings | |
from django.test import TestCase | |
from django.test.simple import DjangoTestSuiteRunner, reorder_suite | |
from django.utils.importlib import import_module | |
from django.utils.unittest.loader import defaultTestLoader | |
class DiscoveryDjangoTestSuiteRunner(DjangoTestSuiteRunner): | |
"""A test suite runner that uses unittest2 test discovery.""" | |
def build_suite(self, test_labels, extra_tests=None, **kwargs): | |
suite = None | |
discovery_root = settings.TEST_DISCOVERY_ROOT | |
if test_labels: | |
suite = defaultTestLoader.loadTestsFromNames(test_labels) | |
# if single named module has no tests, do discovery within it | |
if not suite.countTestCases() and len(test_labels) == 1: | |
suite = None | |
discovery_root = import_module(test_labels[0]).__path__[0] | |
if suite is None: | |
suite = defaultTestLoader.discover( | |
discovery_root, | |
top_level_dir=settings.BASE_PATH, | |
) | |
if extra_tests: | |
for test in extra_tests: | |
suite.addTest(test) | |
return reorder_suite(suite, (TestCase,)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment