Move signal disconnect into finally block

This commit is contained in:
David Cramer 2013-01-11 14:58:36 -08:00
parent d53e3b15ee
commit 6045efa029
1 changed files with 6 additions and 4 deletions

View File

@ -233,12 +233,14 @@ class DeletionTests(TestCase):
def log_post_delete(instance, **kwargs):
self.assertTrue(R.objects.filter(pk=instance.r_id))
models.signals.post_delete.connect(log_post_delete, sender=S)
r = R.objects.create(pk=1)
S.objects.create(pk=1, r=r)
r.delete()
models.signals.post_delete.connect(log_post_delete, sender=S)
try:
r.delete()
finally:
models.signals.post_delete.disconnect(log_post_delete)
@skipUnlessDBFeature("can_defer_constraint_checks")