python test result reporting
Question: My question is regarding python unittest reporting. I am using the xmlrunner
package which produces the xunit output which is used by Jenkins. In addition
to that, I want to either produce an html output or print out the output in a
nice custom format. Note: I already know about HTMLTestRunner and it did not
make me happy. There are 3 problems:

  * my tests are not displayed as suite groups (the report does not show the grouping)
  * the test details are not shown (purpose of the test)
  * the failure stack traces should not be shown in a report that is made for the management

**The question is how to iterate through the test results?**

Here is my test runner code:

    
    
    import unittest
    import os, sys
    import xmlrunner
    
    def getSuites(root):
        testSets = {"ts1":["tc1","tc2"], "ts2":["tc3","tc4"]}
        suites = unittest.TestSuite()
        for ts_name,ts in testSets.iteritems():
            ts_dir = "%s/%s" % (root, ts_name)
            sys.path.append(ts_dir)
            print "ts_dir = %s" % ts_dir
            for tc in ts:
                module = __import__(tc,{},{},['1'])
                suites.addTest(unittest.TestLoader().loadTestsFromModule(module))
        return suites
    
    if __name__ == "__main__":
        root = os.path.dirname(os.path.abspath(__file__))
        suites = getSuites(root)
        results = xmlrunner.XMLTestRunner(output='test_reports').run(suites)
    

Note:

    
    
    for r in results:
        print r
    

throws an exception saying that _XMLTestResult is not iterable. Thanks


Answer: 
    for x in results.successes + results.failures + results.errors:
        print x
        #print x.get_description(), x.outcome
    

