Adding further report options to unittest.py

Discussion in 'Python' started by Marco Bizzarri, Sep 10, 2008.

  1. 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/
    Marco Bizzarri, Sep 10, 2008
    #1
    1. Advertising

  2. Marco Bizzarri wrote:

    > 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?


    Have you looked at nosetests? Nose is a test-discovery & running-framework
    based upon unittest-module (but you can also "only" test simple functions,
    very handy)

    And it has a very powerful plugin-mechanism, that allows you to implement
    cleanly what you want.

    For each test, you get a start/end-method called in your plugin that you can
    use to gather the information you need, e.g. start/stop-times.

    For example, I've created an enhanced reporting plugin that lists all tests
    run (not only those failed or error'ed), and adding time-measuring per-test
    is on my list of todos.

    Diez
    Diez B. Roggisch, Sep 10, 2008
    #2
    1. Advertising

  3. On Wed, Sep 10, 2008 at 3:25 PM, Diez B. Roggisch <> wrote:
    > Marco Bizzarri wrote:
    >
    >> Hi all.
    >>
    >> I would like to change the way test reports are generated, in a Zope
    >> environment.
    >>

    >
    > Have you looked at nosetests? Nose is a test-discovery & running-framework
    > based upon unittest-module (but you can also "only" test simple functions,
    > very handy)


    Nope; next time I will make a google search before posting ;)

    > And it has a very powerful plugin-mechanism, that allows you to implement
    > cleanly what you want.
    >
    > For each test, you get a start/end-method called in your plugin that you can
    > use to gather the information you need, e.g. start/stop-times.



    I gave it a look; it is nice and it seems powerful; I just wonder if I
    need to put my hands on all my tests to do what I want to do... but
    I'm sure this can be sorted in the documentation.


    > For example, I've created an enhanced reporting plugin that lists all tests
    > run (not only those failed or error'ed), and adding time-measuring per-test
    > is on my list of todos.



    Looks like there is a new tool I need to learn... ah, nice times when
    all you needed was an hammer and a screwdriver... ;)


    Thanks for the suggestion, Diez, I'll read it.


    > Diez
    >



    --
    Marco Bizzarri
    http://notenotturne.blogspot.com/
    http://iliveinpisa.blogspot.com/
    Marco Bizzarri, Sep 10, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. aurora
    Replies:
    2
    Views:
    1,414
    aurora
    Jan 27, 2006
  2. Anna Sunny
    Replies:
    0
    Views:
    4,942
    Anna Sunny
    Aug 20, 2006
  3. chrisber
    Replies:
    1
    Views:
    372
    chrisber
    May 2, 2008
  4. Paul  Moore
    Replies:
    1
    Views:
    379
    Paul Moore
    Oct 14, 2008
  5. fossist
    Replies:
    1
    Views:
    977
    Phlip
    Jan 19, 2010
Loading...

Share This Page