Ticket #7884: result_test_runner_r10680.diff

File result_test_runner_r10680.diff, 3.1 KB (added by Arthur Koziel, 16 years ago)

Updated patch for r10680

  • django/test/simple.py

    diff --git a/django/test/simple.py b/django/test/simple.py
    index f3c48ba..488d41e 100644
    a b def reorder_suite(suite, classes):  
    146146        bins[0].addTests(bins[i+1])
    147147    return bins[0]
    148148
    149 def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
     149def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], test_result=None):
    150150    """
    151151    Run the unit tests for all the test labels in the provided list.
    152152    Labels must be of the form:
    def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):  
    163163    A list of 'extra' tests may also be provided; these tests
    164164    will be added to the test suite.
    165165
    166     Returns the number of tests that failed.
     166    If a unittest.TestResult is provided, tests will instead be run and
     167    the TestResult will be updated with results.
     168
     169    Returns the number of tests that failed or errored
    167170    """
    168171    setup_test_environment()
    169172
    def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):  
    189192    old_name = settings.DATABASE_NAME
    190193    from django.db import connection
    191194    connection.creation.create_test_db(verbosity, autoclobber=not interactive)
    192     result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
     195    if test_result:
     196        result = ResultTestRunner(test_result).run(suite)
     197    else:
     198        result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
    193199    connection.creation.destroy_test_db(old_name, verbosity)
    194200
    195201    teardown_test_environment()
    196202
    197203    return len(result.failures) + len(result.errors)
     204
     205class ResultTestRunner(object):
     206    """
     207    TestRunner that uses supplied TestResult to run tests and report results.
     208    """
     209    def __init__(self, test_result):
     210        self.test_result = test_result
     211
     212    def run(self, test):
     213        results = self.test_result
     214        for t in test:
     215            t.run(results)
     216        return results
  • docs/topics/testing.txt

    diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt
    index 5bda3d6..60ec0dd 100644
    a b Defining a test runner  
    11881188By convention, a test runner should be called ``run_tests``. The only strict
    11891189requirement is that it has the same arguments as the Django test runner:
    11901190
    1191 .. function:: run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[])
     1191.. function:: run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], test_result=None)
    11921192
    11931193    ``test_labels`` is a list of strings describing the tests to be run. A test
    11941194    label can take one of three forms:
    requirement is that it has the same arguments as the Django test runner:  
    12151215    suite that is executed by the test runner. These extra tests are run
    12161216    in addition to those discovered in the modules listed in ``module_list``.
    12171217
    1218     This method should return the number of tests that failed.
     1218    If ``test_result`` is supplied a ``unittest.TestResult``, then tests run
     1219    will save results in this ``TestResult``. Otherwise this method should
     1220    return the number of tests that failed.
    12191221
    12201222Testing utilities
    12211223-----------------
Back to Top