[TIP] Handling exceptions while cleaning up in SuiteFixture Setup

Olemis Lang olemis at gmail.com
Mon Aug 31 10:51:02 PDT 2009


I have a doubt about how to implementing *CORRECTLY* a feature in
`dutest`. The doubt is not related to the internal details of the
module, in fact, the subject is a little bit more general.

In `dutest` there's a suite that contains one test
case for each interactive example that's been written in docstrings ...
I am trying to implement `Suite Fixture Setup` pattern [1]_ [2]_ in
there. I mean, since both `setUp` and `tearDown` operate at the test
case level, they are invoked on executing each individual example.
What I want to do is to call `setUp` (a new `setUp` method at the
test suite) once before executing any example, and the suite's
`tearDown` method after all examples have been run.

I saw something *LIKE* that implemented for unittests in Trac,
but the code doesn't handle failures while preparing or cleaning
up the fixture.

The solution I gave to this problem is similar to `TestCase.run`. In
this case, if an exception is raised from inside the suite's
`setUp` method then an error is reported for each test case
it contains, since that means that none of them can be run either.

So far everything's Ok, but :

  - What should be done if an exception is raised from inside
    the suite's `tearDown` method ?

In this case the result for each test case is already determined,
but the failure happens after everything has been done. So I don't
have an answer so far ; and neither G. Meszaros' book [1]_
nor NUnit [3]_ nor JUnit [4]_ mention anything about that either :-/
(i.e. the later two even seem to have different semantics :-/ ).

I suppose there are at least a few framework that implement this
kind of feature already. So I was wondering :

  - What should happen when an exception is raised from inside
    the suite's `tearDown` method ?

Thnx in advance ! I'm sure that any idea you have will be much
better than mine right now ( nothing ! ) .

.. [1] "XUnit test patterns : refactoring test code", Gerard Meszaros
        ISBN-13: 978-0-13-149505-0, The Addison-Wesley Signature Series

.. [2] SuiteFixture Setup
        (http://xunitpatterns.com/SuiteFixture%20Setup.html)

.. [3] TestFixtureTearDownAttribute (NUnit 2.1 / 2.5)
        (http://nunit.org/index.php?p=fixtureTeardown&r=2.5)

.. [4] Annotation Type AfterClass
        (http://junit.org/apidocs/org/junit/AfterClass.html)

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:



More information about the testing-in-python mailing list