def test_custodian_function_param_other(self): while gc.collect(): pass SomeObject_count_before = foo.SomeObject.instance_count Foobar_count1 = foo.Foobar.instance_count obj1 = foo.SomeObject("xxx") foo1 = foo.create_new_foobar() foo.set_foobar_with_other_as_custodian(foo1, obj1) Foobar_count2 = foo.Foobar.instance_count ## now, deleting foo1 should keep Foobar count the same, since ## obj1 is keeping it alive del foo1 while gc.collect(): pass self.assertEqual(foo.Foobar.instance_count, Foobar_count2) ## now deleting obj1 should cause both foo1 and obj1 to be destroyed del obj1 while gc.collect(): pass self.assertEqual(foo.SomeObject.instance_count, SomeObject_count_before) self.assertEqual(foo.Foobar.instance_count, Foobar_count1)