[TIP] always call teardownX even if setupX fails?

holger krekel holger at merlinux.eu
Thu Jan 28 05:31:16 PST 2010

On Thu, Jan 28, 2010 at 23:47 +1100, Robert Collins wrote:
> On Thu, 2010-01-28 at 13:10 +0100, holger krekel wrote:
> > 
> > 
> > not calling teardown seemed slightly easier to implement ... i can
> > work
> > a bit harder though :) 
> > 
> > However, I haven't see your example pattern with py.test usages yet.  
> > Is this a an example from actual code? 
> Broadly yes. Usually seen more like this in fact:
> class A
>    setUp(): does stuff
> class B(A):
>    setUp(): check if we should skip

If you can you'd probably first try to see if to skip and then 
call the base class' setUp(), though.  Anyway, ... 
> > And if so do you have have and use it in setup_module and setup_class
> > - alike 
> > methods?
> I don't use such methods, so no (see prior conversation about decoupling
> resources etc).

... these cases were what seemed complicated to me. 
However, it turned out, my previous implementation was buggy anyway! 
So now there is no special casing for Skip anymore and teardown gets called
in all cases - and i also refined the "setup_module/class" calling to  
only happen exactly once (before they'd be happen multiple times for each
test if they raised an error).  Also added two functional and one unit-test
and hope things are settled now :) 

many thanks for your feedback and insistance on clarity here! 


More information about the testing-in-python mailing list