<div dir="ltr"><div><div><div><div>Hi All,<br><br></div>I found that pytest 2.5.2 doesn't finalize all fixtures. E.g. we have function and class level fixtures. In case func level fixture raises an exception, class level fixture finalization won't be called.<br>
</div>SetupState._callfinalizers takes care only about finalizing of all fixtures with the same level.<br><br></div><div>I didn't find any way to workaround this without modifying pytest code.<br></div><div><br></div>
Here is my fix:<br><div>1. add self.finalizer_exception=None attribute.<br></div><div>2. Modify _callfinalizers<br></div><div>def _callfinalizers(self, colitem):<br> finalizers = self._finalizers.pop(colitem, None)<br>
while finalizers:<br> fin = finalizers.pop()<br> try:<br> fin()<br> except (Exception, KeyboardInterrupt):<br> # XXX Only first exception will be seen by user,<br> # ideally all should be reported.<br>
if self.finalizer_exception is None:<br> self.finalizer_exception = sys.exc_info()<br> if self.finalizer_exception and not self._finalizers:<br> py.builtin._reraise(*self.finalizer_exception)<br>
<br><br></div><div>What do you think about this? Have I missed something? I assume that there could be another way to resolve the issue.<br></div><br></div>Thank you in advance!<br>Anton<br></div>