title: Get the docstring of the test methods from a result of unit testing
body: <p>I want to test uploaded python programs with the <code>unittest</code> module on a django based web site and give a useful feedback to the student. I created some helper function to get statistics (how many failures and errors) and messages. </p>
  
  <pre><code>def suite(*test_cases):
      suites = [unittest.makeSuite(case) for case in test_cases]
      return unittest.TestSuite(suites)
  
  
  def testcase_statistics_and_messages(*test_cases):
      devnull = open('/dev/null', "w")
      runner = unittest.TextTestRunner(stream=devnull)
      test_suite = suite(*test_cases)
      test_result = runner.run(test_suite)
      devnull.close()
  
      failure_messages = [mesg for test_case, mesg in test_result.failures]
      number_of_failures = len(failure_messages)
      error_messages = [mesg for test_case, mesg in test_result.errors]
      number_of_errors = len(error_messages)
      number_of_test_cases = test_suite.countTestCases()
      number_of_successes = (number_of_test_cases
                             - number_of_errors - number_of_failures)
  
      return dict(
          number_of_test_cases=number_of_test_cases,
          failure_messages=failure_messages,
          error_messages=error_messages,
          number_of_successes=number_of_successes,
          number_of_errors=number_of_errors,
          number_of_failures=number_of_failures,
      )
  </code></pre>
  
  <p>I save the program of the student and the unit tests into a file. I import the file, and I get the list of the TestCase classes from the file, and run the functions above. (I can handle SyntaxError, IndentationError and runtime errors of the program uploaded by the student.)</p>
  
  <p>However the messages I got from the unit tests are not too useful for the students. E.g.</p>
  
  <pre><code>Traceback (most recent call last):
    File "/tmp/tmpnda6x_60.py", line 39, in test_discriminant_returns_the_proper_values
      self.assertEqual(discriminant(*args), return_values)
  AssertionError: -2 != 0
  </code></pre>
  
  <p>If I would get for example the docstring of the test method of the <code>TestCase</code>, I would be happy. I can not find a straightforward way to do this. If I would get the name of the TestCase and the method, I could get the docstring with the <code>eval</code> function. Is there an easier way, than to get the test method names from the messages and go through the TestCases and check whether there is a test method called like I have found in the message.</p>
  
  <p>I have tried to use <code>msg</code> keyword arguments to the asserts, but than it is a pain to write unit tests, and I need to use e.g. regular expression to get the informative part of the message.</p>
  
  <p>I have Python 3.2 on the server I want to run this django project on.</p>