Adding further report options to unittest.py

Marco Bizzarri marco.bizzarri at gmail.com
Wed Sep 10 15:19:11 CEST 2008


Hi all.

I would like to change the way test reports are generated, in a Zope
environment.

I'm playing with TextTestReport, TextTestRunner. Since things are
getting to complicated, I'm afraid I'm following a non-pythonic way.

Specifically, I would like to have an output like:

package.subpackage.test_module.TestCase 0.1

where 0.1 is the time spent into doing the test.

In a previous attempt, I made the tests print the number of the test
executed, so that I would have the following output:

1 package.subpackage.test_module.TestCase

however, to do this, I had to put things in the following way:


class PAFlowTestRunner(TextTestRunner):
    def _makeResult(self):
        return PAFlowTextResult(self.stream, self.descriptions, self.verbosity)

class PAFlowTextResult(_TextTestResult):

    def startTest(self, test):
        self.stream.write("%s " % self.testsRun)
        _TextTestResult.startTest(self, test)


now, of course, this is ugly, because I'm using _TextTestResult, which
I'm not supposed to know, and I'm changing behaviour by subclassing,
which is not exactly what I would like to do.

What is the pythonic way to accomplish this?

Marco
-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/



More information about the Python-list mailing list