Ticket #16534: djangotestsuiterunner-4.diff

File djangotestsuiterunner-4.diff, 4.7 KB (added by jcd, 2 years ago)

Added documentation updates suggested on IRC by timograham

  • django/test/runner.py

    diff --git a/django/test/runner.py b/django/test/runner.py
    index 84fe249..5ff3f15 100644
    a b class DiscoverRunner(object): 
    1414    A Django test runner that uses unittest2 test discovery.
    1515    """
    1616
     17    test_suite = 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.test_suite()
    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/releases/1.7.txt

    diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt
    index 32b5e91..326986c 100644
    a b Templates 
    276276  :setting:`TEMPLATE_DEBUG` is ``True``. This allows template origins to be
    277277  inspected and logged outside of the ``django.template`` infrastructure.
    278278
     279Tests
     280^^^^^
     281
     282* :class:`~django.test.runner.DiscoverRunner` has two new attributes,
     283  :attr:`test_suite` and :attr:`test_runner`, which facilitate
     284  overriding the way tests are collected and run.  Documentation has been
     285  added for the similar :attr:`test_loader` attribute
     286  which has been in place since 1.6.
     287
     288
    279289Backwards incompatible changes in 1.7
    280290=====================================
    281291
  • docs/topics/testing/advanced.txt

    diff --git a/docs/topics/testing/advanced.txt b/docs/topics/testing/advanced.txt
    index d8d59c6..2195f9a 100644
    a b Defining a test runner 
    299299.. currentmodule:: django.test.runner
    300300
    301301A test runner is a class defining a ``run_tests()`` method. Django ships
    302 with a ``DiscoverRunner`` class that defines the default Django
    303 testing behavior. This class defines the ``run_tests()`` entry point,
    304 plus a selection of other methods that are used to by ``run_tests()`` to
    305 set up, execute and tear down the test suite.
     302with a ``DiscoverRunner`` class that defines the default Django testing
     303behavior. This class defines the ``run_tests()`` entry point, plus a
     304selection of other methods that are used to by ``run_tests()`` to set up,
     305execute and tear down the test suite.
    306306
    307307.. class:: DiscoverRunner(pattern='test*.py', top_level=None, verbosity=1, interactive=True, failfast=True, **kwargs)
    308308
     309.. versionadded:: 1.6
     310
    309311    ``DiscoverRunner`` will search for tests in any file matching ``pattern``.
    310312
    311313    ``top_level`` can be used to specify the directory containing your
    set up, execute and tear down the test suite. 
    339341Attributes
    340342~~~~~~~~~~
    341343
     344.. attribute:: DicsoverRunner.test_suite
     345
     346.. versionadded:: 1.7
     347
     348    The class used to build the test suite.  By default it is set to
     349    ``unittest.TestSuite``.  This can be overridden if you wish to implement
     350    different logic for collecting tests into a test suite.
     351
     352.. attribute:: DiscoverRunner.test_runner
     353
     354.. versionadded:: 1.7
     355
     356    This is the class of the low-level test runner which is used to execute
     357    the individual tests and format the results.  By default it is set to
     358    ``unittest.TextTestRunner``.  Despite the unfortunate similarity in
     359    naming conventions, this is not the same type of class as
     360    ``DiscoverRunner``, which covers a broader set of responsibilites.  You
     361    can override this attribute to modify the way tests are run and reported.
     362
     363.. attribute:: DiscoverRunner.test_loader
     364
     365.. versionadded:: 1.6
     366
     367    This is the class that loads tests, whether from TestCases or modules or
     368    otherwise and bundles them into test suites for the runner to execute. 
     369    By default it is set to ``unittest.defaultTestLoader``.  You can override
     370    this attribute if your tests are going to be loaded in unusual ways.
     371
    342372.. attribute:: DiscoverRunner.option_list
    343373
    344374    This is the tuple of ``optparse`` options which will be fed into the
Back to Top