Ticket #7884: result_test_runner_r8055.diff

File result_test_runner_r8055.diff, 2.8 KB (added by devin, 16 years ago)

patch and doc changes

  • django/test/simple.py

     
    100100    else: # label is app.TestClass.test_method
    101101        return TestClass(parts[2])
    102102
    103 def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
     103def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], test_result=None):
    104104    """
    105105    Run the unit tests for all the test labels in the provided list.
    106106    Labels must be of the form:
     
    117117    A list of 'extra' tests may also be provided; these tests
    118118    will be added to the test suite.
    119119   
    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
    121124    """
    122125    setup_test_environment()
    123126   
     
    140143
    141144    old_name = settings.DATABASE_NAME
    142145    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)
    144150    destroy_test_db(old_name, verbosity)
    145151   
    146152    teardown_test_environment()
    147153   
    148154    return len(result.failures) + len(result.errors)
     155
     156class 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

     
    989989By convention, a test runner should be called ``run_tests``. The only strict
    990990requirement is that it has the same arguments as the Django test runner:
    991991
    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)``
    993993
    994994    ``test_labels`` is a list of strings describing the tests to be run. A test
    995995    label can take one of three forms:
     
    10141014    ``extra_tests`` is a list of extra ``TestCase`` instances to add to the
    10151015    suite that is executed by the test runner. These extra tests are run
    10161016    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``.
    10171020
    10181021    This method should return the number of tests that failed.
    10191022
Back to Top