Ticket #16534: djangotestsuiterunner-3.diff

File djangotestsuiterunner-3.diff, 3.0 KB (added by jcd, 22 months ago)

New patch that works with DiscoverRunner instead of DjangoTestSuiteRunner

  • django/test/runner.py

    diff --git a/django/test/runner.py b/django/test/runner.py
    index 84fe249..e1a6863 100644
    a b class DiscoverRunner(object): 
    1414    A Django test runner that uses unittest2 test discovery.
    1515    """
    1616
     17    suite_class = TestSuite
     18    test_runner = unittest.TextTestRunner
    1719    test_loader = defaultTestLoader
    1820    reorder_by = (TestCase, )
    1921    option_list = (
    class DiscoverRunner(object): 
    4244        unittest.installHandler()
    4345
    4446    def build_suite(self, test_labels=None, extra_tests=None, **kwargs):
    45         suite = TestSuite()
     47        suite = self.suite_class()
    4648        test_labels = test_labels or ['.']
    4749        extra_tests = extra_tests or []
    4850
    class DiscoverRunner(object): 
    107109        return setup_databases(self.verbosity, self.interactive, **kwargs)
    108110
    109111    def run_suite(self, suite, **kwargs):
    110         return unittest.TextTestRunner(
     112        return self.test_runner(
    111113            verbosity=self.verbosity,
    112114            failfast=self.failfast,
    113115        ).run(suite)
    def reorder_suite(suite, classes): 
    201203    classes[1], etc. Tests with no match in classes are placed last.
    202204    """
    203205    class_count = len(classes)
    204     bins = [unittest.TestSuite() for i in range(class_count+1)]
     206    suite_class = type(suite)
     207    bins = [suite_class() for i in range(class_count+1)]
    205208    partition_suite(suite, classes, bins)
    206209    for i in range(class_count):
    207210        bins[0].addTests(bins[i+1])
  • docs/topics/testing/advanced.txt

    diff --git a/docs/topics/testing/advanced.txt b/docs/topics/testing/advanced.txt
    index d8d59c6..0adde3e 100644
    a b set up, execute and tear down the test suite. 
    339339Attributes
    340340~~~~~~~~~~
    341341
     342.. attribute:: DicsoverRunner.suite_class
     343
     344    The class used to build the test suite.  By default it is set to
     345    ``unittest.TestSuite``.  This can be overridden if you wish to implement
     346    different logic for collecting tests into a test suite.
     347
     348.. attribute:: DiscoverRunner.test_runner
     349
     350    This is the class of the low-level test runner which is used to execute
     351    the individual tests and format the results.  By default it is set to
     352    ``unittest.TextTestRunner``.  Despite the unfortunate similarity in
     353    naming conventions, this is not the same type of class as
     354    ``DiscoverRunner``, which covers a broader set of responsibilites.  You
     355    can override this attribute to modify the way tests are run and reported.
     356
     357.. attribute:: DiscoverRunner.test_loader
     358
     359    This is the class that loads tests, whether from TestCases or modules or
     360    otherwise and bundles them into test suites for the runner to execute. 
     361    By default it is set to ``unittest.defaultTestLoader``.  You can override
     362    this attribute if your tests are going to be loaded in unusual ways.
     363
    342364.. attribute:: DiscoverRunner.option_list
    343365
    344366    This is the tuple of ``optparse`` options which will be fed into the
Back to Top