[Python-ideas] Test Class setup and teardown in unittest

Nikolaus Rath Nikolaus at rath.org
Thu Jan 21 03:49:56 CET 2010

Mark Roddy <markroddy at gmail.com> writes:
> Earlier this week on the Testing In Python list, there was a
> discussion on how to execute a setup and/or teardown for a single test
> class instead of for each test fixture on the class (see the 'setUp
> and tearDown behavior' thread).  I have had to deal with situation
> myself before, and I am obviously not the only one (since I did not
> initiate the thread).  As such I'd like to propose adding a class
> level setup and tear down method the unittest TestCase class.
> Rationale:
> Test cases can at times require the setup of expensive resources.
> This is often the case when implementing integration testing.  Having

I think this is a great idea, I ran into this problem too.

> * What should the methods be called? setup_class and teardown_class or
> setupClass and teardownClass? For consistency with existing methods
> the camelCase should probably be used.
> * If the setupClass fails how should the error be reported? The
> *easiest* way is for the failure to be reported as part of the first
> test
> * Ditto for teardownClass - again the easiest way is for it to be
> reported as a failure in the last test
> * If setupClass fails then should all the tests in that class be
> skipped? I think yes.

No strong feelings about this, I'm happy as long as some solution gets


 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C

More information about the Python-ideas mailing list