diff --git a/bindings/pyroot/pythonizations/test/tseqcollection_itemaccess.py b/bindings/pyroot/pythonizations/test/tseqcollection_itemaccess.py index 5d6a1e26c28cc..57b15334edfad 100644 --- a/bindings/pyroot/pythonizations/test/tseqcollection_itemaccess.py +++ b/bindings/pyroot/pythonizations/test/tseqcollection_itemaccess.py @@ -125,6 +125,10 @@ def test_setitem(self): with self.assertRaises(TypeError): sc[1.0] = ROOT.TObject() + # Clear before the added element might be garbage collected, + # to avoid dangling pointer access. + sc.Clear() + def test_setitem_slice(self): sc1 = self.create_tseqcollection() sc2 = self.create_tseqcollection() @@ -239,6 +243,8 @@ def test_delitem(self): with self.assertRaises(TypeError): del sc[1.0] + sc.Clear() + def test_delitem_slice(self): # Delete all items sc1 = self.create_tseqcollection()