From ed070e0769c4ac3efda05448db8846f61dae255c Mon Sep 17 00:00:00 2001 From: David Glick Date: Fri, 18 Aug 2023 16:04:22 -0700 Subject: [PATCH] unregister handler even if test fails (#1680) * unregister handler even if test fails * changelog --- news/1680.internal | 1 + src/plone/restapi/tests/test_content_utils.py | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 news/1680.internal diff --git a/news/1680.internal b/news/1680.internal new file mode 100644 index 0000000000..a6b2e232e2 --- /dev/null +++ b/news/1680.internal @@ -0,0 +1 @@ +Fix test cleanup. @davisagli diff --git a/src/plone/restapi/tests/test_content_utils.py b/src/plone/restapi/tests/test_content_utils.py index 055522a86f..c9911335cf 100644 --- a/src/plone/restapi/tests/test_content_utils.py +++ b/src/plone/restapi/tests/test_content_utils.py @@ -92,9 +92,10 @@ def move_object(event): sm.registerHandler(move_object, (IObjectAddedEvent,)) - obj = create(self.folder, "Document", "my-document") - notify(ObjectCreatedEvent(obj)) - obj = add(self.folder, obj) - self.assertEqual(aq_parent(obj), self.portal) - - sm.unregisterHandler(move_object, (IObjectAddedEvent,)) + try: + obj = create(self.folder, "Document", "my-document") + notify(ObjectCreatedEvent(obj)) + obj = add(self.folder, obj) + self.assertEqual(aq_parent(obj), self.portal) + finally: + sm.unregisterHandler(move_object, (IObjectAddedEvent,))