[python] take care to this detail of @contextmanager: if an unhandled exception occurs in the block, it is reraised inside the generator at the point where the yield occurred
--- a/devtools/testlib.py Thu Apr 01 08:24:11 2010 +0200
+++ b/devtools/testlib.py Thu Apr 01 08:24:53 2010 +0200
@@ -360,9 +360,11 @@
self.vreg._loadedmods.setdefault(self.__module__, {})
for obj in appobjects:
self.vreg.register(obj)
- yield
- for obj in appobjects:
- self.vreg.unregister(obj)
+ try:
+ yield
+ finally:
+ for obj in appobjects:
+ self.vreg.unregister(obj)
# vregistry inspection utilities ###########################################
--- a/server/sources/native.py Thu Apr 01 08:24:11 2010 +0200
+++ b/server/sources/native.py Thu Apr 01 08:24:53 2010 +0200
@@ -482,10 +482,12 @@
except AttributeError:
assert event == 'deleted'
getattr(storage, 'entity_deleted')(entity, attr)
- yield # 2/ execute the source's instructions
- # 3/ restore original values
- for attr, value in orig_values.items():
- entity[attr] = value
+ try:
+ yield # 2/ execute the source's instructions
+ finally:
+ # 3/ restore original values
+ for attr, value in orig_values.items():
+ entity[attr] = value
def add_entity(self, session, entity):
"""add a new entity to the source"""