Ticket #7884: result_test_runner_r8055.diff
File result_test_runner_r8055.diff, 2.8 KB (added by , 16 years ago) |
---|
-
django/test/simple.py
100 100 else: # label is app.TestClass.test_method 101 101 return TestClass(parts[2]) 102 102 103 def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[] ):103 def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], test_result=None): 104 104 """ 105 105 Run the unit tests for all the test labels in the provided list. 106 106 Labels must be of the form: … … 117 117 A list of 'extra' tests may also be provided; these tests 118 118 will be added to the test suite. 119 119 120 Returns the number of tests that failed. 120 If a unittest.TestResult is provided, tests will instead be run and 121 the TestResult will be updated with results. 122 123 Returns the number of tests that failed or errored 121 124 """ 122 125 setup_test_environment() 123 126 … … 140 143 141 144 old_name = settings.DATABASE_NAME 142 145 create_test_db(verbosity, autoclobber=not interactive) 143 result = unittest.TextTestRunner(verbosity=verbosity).run(suite) 146 if test_result: 147 result = ResultTestRunner(test_result).run(suite) 148 else: 149 result = unittest.TextTestRunner(verbosity=verbosity).run(suite) 144 150 destroy_test_db(old_name, verbosity) 145 151 146 152 teardown_test_environment() 147 153 148 154 return len(result.failures) + len(result.errors) 155 156 class ResultTestRunner(object): 157 """ 158 TestRunner that uses supplied TestResult to run tests and report results. 159 """ 160 161 def __init__(self, test_result): 162 self.test_result = test_result 163 164 def run(self, test): 165 results = self.test_result 166 for t in test: 167 t.run(results) 168 return results -
docs/testing.txt
989 989 By convention, a test runner should be called ``run_tests``. The only strict 990 990 requirement is that it has the same arguments as the Django test runner: 991 991 992 ``run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[] )``992 ``run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], test_result=None)`` 993 993 994 994 ``test_labels`` is a list of strings describing the tests to be run. A test 995 995 label can take one of three forms: … … 1014 1014 ``extra_tests`` is a list of extra ``TestCase`` instances to add to the 1015 1015 suite that is executed by the test runner. These extra tests are run 1016 1016 in addition to those discovered in the modules listed in ``module_list``. 1017 1018 If ``test_result`` is supplied a ``unittest.TestResult``, then tests run 1019 will save results in this ``TestResult``. 1017 1020 1018 1021 This method should return the number of tests that failed. 1019 1022