SO-17664702: call fixture finalizers even if the fixture function

partially failed (finalizers would not always be called before)
This commit is contained in:
holger krekel
2013-07-17 10:29:11 +02:00
parent c53556b88d
commit 1280add047
5 changed files with 52 additions and 10 deletions

View File

@@ -1290,15 +1290,21 @@ class FixtureRequest(FuncargnamesCompatAttr):
# route request.addfinalizer to fixturedef
mp.setattr(self, "addfinalizer", fixturedef.addfinalizer)
# perform the fixture call
val = fixturedef.execute(request=self)
try:
# perform the fixture call
val = fixturedef.execute(request=self)
finally:
# if the fixture function failed it might still have
# registered finalizers so we can register
# prepare finalization according to scope
# (XXX analyse exact finalizing mechanics / cleanup)
self.session._setupstate.addfinalizer(fixturedef.finish, self.node)
self._fixturemanager.addargfinalizer(fixturedef.finish, argname)
for subargname in fixturedef.argnames: # XXX all deps?
self._fixturemanager.addargfinalizer(fixturedef.finish, subargname)
# prepare finalization according to scope
# (XXX analyse exact finalizing mechanics / cleanup)
self.session._setupstate.addfinalizer(fixturedef.finish,
self.node)
self._fixturemanager.addargfinalizer(fixturedef.finish, argname)
for subargname in fixturedef.argnames: # XXX all deps?
self._fixturemanager.addargfinalizer(fixturedef.finish,
subargname)
mp.undo()
return val