title: Python 3 unittest: How to extract results of tests?
body: <p>I am using Python's (3.4.1) <code>unittest</code> module for my unit tests.</p>
  
  <p>I load all my testing module files using imports and then run unittest.main():</p>
  
  <pre><code>import unittest
  import testing_module1
  import testing_module2
  # [...]
  if __name__ == '__main__':
      unittest.main()
  </code></pre>
  
  <p>This works perfectly for me as it is simple and respect the command line arguments I use to control verbosity or which test(s) to run.</p>
  
  <p>I want to continue to output the same information, but I would like to generate an XML file from the results. I tried xmlrunner (<a href="https://github.com/xmlrunner/unittest-xml-reporting/" rel="nofollow">https://github.com/xmlrunner/unittest-xml-reporting/</a>) but:</p>
  
  <ul>
  <li>it does not output as much info to stdout as the standard runner;</li>
  <li>it uses a specific format of the XML that doesn't suites me.</li>
  </ul>
  
  <p>I would like to generate the XML (I don't mind doing it manually) with the format I need but with minimal change to how the tests are run.</p>
  
  <p>What are my options?</p>
  
  <ol>
  <li>I could write my own TestRunner but I don't want to re-write everything, I just want to add extra output to the actual runner with minimal code change.</li>
  <li>I could inherit unittest.TextTestRunner but I fear that adding XML output to it would require re-writing every methods, loosing the advantage of inheritance in the first place.</li>
  <li>I could try to extract the test results after the call to <code>unittest.main()</code> and parse it. The problem here is that <code>unittest.main()</code> seems to exit when it's done so any code after it is not executed.</li>
  </ol>
  
  <p>Any suggestion?</p>
  
  <p>Thanks!</p>