Ticket #16534: djangotestsuiterunner-4.diff​

File djangotestsuiterunner-4.diff​, 4.7 KB (added by Cliff Dyer, 11 years ago)

Added documentation updates suggested on IRC by timograham (edited to fix a documentation typo: DicsoverRunner)

Line 
1diff --git a/django/test/runner.py b/django/test/runner.py
2index 84fe249..5ff3f15 100644
3--- a/django/test/runner.py
4+++ b/django/test/runner.py
5@@ -14,6 +14,8 @@ class DiscoverRunner(object):
6 A Django test runner that uses unittest2 test discovery.
7 """
8
9+ test_suite = TestSuite
10+ test_runner = unittest.TextTestRunner
11 test_loader = defaultTestLoader
12 reorder_by = (TestCase, )
13 option_list = (
14@@ -42,7 +44,7 @@ class DiscoverRunner(object):
15 unittest.installHandler()
16
17 def build_suite(self, test_labels=None, extra_tests=None, **kwargs):
18- suite = TestSuite()
19+ suite = self.test_suite()
20 test_labels = test_labels or ['.']
21 extra_tests = extra_tests or []
22
23@@ -107,7 +109,7 @@ class DiscoverRunner(object):
24 return setup_databases(self.verbosity, self.interactive, **kwargs)
25
26 def run_suite(self, suite, **kwargs):
27- return unittest.TextTestRunner(
28+ return self.test_runner(
29 verbosity=self.verbosity,
30 failfast=self.failfast,
31 ).run(suite)
32@@ -201,7 +203,8 @@ def reorder_suite(suite, classes):
33 classes[1], etc. Tests with no match in classes are placed last.
34 """
35 class_count = len(classes)
36- bins = [unittest.TestSuite() for i in range(class_count+1)]
37+ suite_class = type(suite)
38+ bins = [suite_class() for i in range(class_count+1)]
39 partition_suite(suite, classes, bins)
40 for i in range(class_count):
41 bins[0].addTests(bins[i+1])
42diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt
43index 32b5e91..326986c 100644
44--- a/docs/releases/1.7.txt
45+++ b/docs/releases/1.7.txt
46@@ -276,6 +276,16 @@ Templates
47 :setting:`TEMPLATE_DEBUG` is ``True``. This allows template origins to be
48 inspected and logged outside of the ``django.template`` infrastructure.
49
50+Tests
51+^^^^^
52+
53+* :class:`~django.test.runner.DiscoverRunner` has two new attributes,
54+ :attr:`test_suite` and :attr:`test_runner`, which facilitate
55+ overriding the way tests are collected and run. Documentation has been
56+ added for the similar :attr:`test_loader` attribute
57+ which has been in place since 1.6.
58+
59+
60 Backwards incompatible changes in 1.7
61 =====================================
62
63diff --git a/docs/topics/testing/advanced.txt b/docs/topics/testing/advanced.txt
64index d8d59c6..2195f9a 100644
65--- a/docs/topics/testing/advanced.txt
66+++ b/docs/topics/testing/advanced.txt
67@@ -299,13 +299,15 @@ Defining a test runner
68 .. currentmodule:: django.test.runner
69
70 A test runner is a class defining a ``run_tests()`` method. Django ships
71-with a ``DiscoverRunner`` class that defines the default Django
72-testing behavior. This class defines the ``run_tests()`` entry point,
73-plus a selection of other methods that are used to by ``run_tests()`` to
74-set up, execute and tear down the test suite.
75+with a ``DiscoverRunner`` class that defines the default Django testing
76+behavior. This class defines the ``run_tests()`` entry point, plus a
77+selection of other methods that are used to by ``run_tests()`` to set up,
78+execute and tear down the test suite.
79
80 .. class:: DiscoverRunner(pattern='test*.py', top_level=None, verbosity=1, interactive=True, failfast=True, **kwargs)
81
82+.. versionadded:: 1.6
83+
84 ``DiscoverRunner`` will search for tests in any file matching ``pattern``.
85
86 ``top_level`` can be used to specify the directory containing your
87@@ -339,6 +341,34 @@ set up, execute and tear down the test suite.
88 Attributes
89 ~~~~~~~~~~
90
91+.. attribute:: DiscoverRunner.test_suite
92+
93+.. versionadded:: 1.7
94+
95+ The class used to build the test suite. By default it is set to
96+ ``unittest.TestSuite``. This can be overridden if you wish to implement
97+ different logic for collecting tests into a test suite.
98+
99+.. attribute:: DiscoverRunner.test_runner
100+
101+.. versionadded:: 1.7
102+
103+ This is the class of the low-level test runner which is used to execute
104+ the individual tests and format the results. By default it is set to
105+ ``unittest.TextTestRunner``. Despite the unfortunate similarity in
106+ naming conventions, this is not the same type of class as
107+ ``DiscoverRunner``, which covers a broader set of responsibilites. You
108+ can override this attribute to modify the way tests are run and reported.
109+
110+.. attribute:: DiscoverRunner.test_loader
111+
112+.. versionadded:: 1.6
113+
114+ This is the class that loads tests, whether from TestCases or modules or
115+ otherwise and bundles them into test suites for the runner to execute.
116+ By default it is set to ``unittest.defaultTestLoader``. You can override
117+ this attribute if your tests are going to be loaded in unusual ways.
118+
119 .. attribute:: DiscoverRunner.option_list
120
121 This is the tuple of ``optparse`` options which will be fed into the
Back to Top