R. David Murray added the comment:

As further motivation, I actually tried to implement this using try/except.  
First I wrote a loop in tearDownClass that ran each of the cleanups inside a 
try/except and printed the exception if there was one.  But of course that 
doesn't run if setUpClass fails.  So I started to add a similar try/except loop 
in setUpClass...and then realized that in order to have the cleanups run 
correctly, I needed to add each cleanup to a list on the class if and only if 
the corresponding setup succeeded, and then run only those cleanups in the 
tearDownClass.

So, I ended up implementing addClassCleanup.  However, in order to make it 
generic (I have two classes where I need it currently, and will probably be 
adding more), I have a base class with setUpClass that calls a safeSetUpClass 
inside a try/except, my safeSetUpClass on the actual test class does the setup 
and calls to addClassCleanUp, and my tearDownClass does the loop over the 
accumulated cleanups.

So, yeah, it would be really handy to have this as an actual feature :)

----------
keywords: +easy

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24412>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to