@@ -356,15 +356,15 @@ def test_pyobject_dump(self):
356356
357357 def test_object_clear_managed_dict (self ):
358358 # PyObject_ClearManagedDict
359- clear = _testcapi .pyobject_clear_managed_dict
359+ clear_managed_dict = _testcapi .pyobject_clear_managed_dict
360360 ManagedDictType = _testcapi .ManagedDictType
361361
362362 obj = ManagedDictType ()
363363 obj .value = 'first'
364364 # asserting `__dict__` is a must to materialize the value before clean:
365365 self .assertEqual (obj .__dict__ , {'value' : 'first' })
366366 self .assertIs (type (obj .__dict__ ), dict )
367- clear (obj )
367+ clear_managed_dict (obj )
368368 self .assertEqual (obj .__dict__ , {})
369369 self .assertIs (type (obj .__dict__ ), dict )
370370
@@ -373,40 +373,43 @@ def test_object_clear_managed_dict(self):
373373 existing_dict = {f'attr_{ x } ' : x for x in range (100 )}
374374 obj .__dict__ = existing_dict
375375 self .assertIs (obj .__dict__ , existing_dict )
376- clear (obj )
376+ clear_managed_dict (obj )
377377 self .assertEqual (obj .__dict__ , {})
378378 self .assertIs (type (obj .__dict__ ), dict )
379379
380380 # empty dict:
381381 obj = ManagedDictType ()
382382 self .assertEqual (obj .__dict__ , {})
383383 self .assertIs (type (obj .__dict__ ), dict )
384- clear (obj )
384+ clear_managed_dict (obj )
385385 self .assertEqual (obj .__dict__ , {})
386386 self .assertIs (type (obj .__dict__ ), dict )
387387
388388 # double clear:
389389 obj = ManagedDictType ()
390390 obj .value = 'first'
391391 self .assertEqual (obj .__dict__ , {'value' : 'first' })
392- clear (obj )
393- clear (obj )
392+ clear_managed_dict (obj )
393+ clear_managed_dict (obj )
394394 self .assertEqual (obj .__dict__ , {})
395395 self .assertIs (type (obj .__dict__ ), dict )
396396
397397 # unmaterialized:
398398 obj = ManagedDictType ()
399399 obj .value = 'first'
400- clear (obj )
400+ clear_managed_dict (obj )
401401 self .assertEqual (obj .__dict__ , {})
402402 self .assertIs (type (obj .__dict__ ), dict )
403403
404- # CRASHES: clear (NULL)
404+ # CRASHES: clear_managed_dict (NULL)
405405
406406 @threading_helper .requires_working_threading ()
407+ @support .nomemtest
407408 def test_object_clear_managed_dict_ft_memory_error (self ):
408409 # PyObject_ClearManagedDict, gh-152254
409- clear = _testcapi .pyobject_clear_managed_dict
410+ # The setup must contain: object owned by another thread
411+ # and the attempt to clear the managed dict with no memory left
412+ clear_managed_dict = _testcapi .pyobject_clear_managed_dict
410413 ManagedDictType = _testcapi .ManagedDictType
411414
412415 obj = ManagedDictType ()
@@ -416,8 +419,8 @@ def test_object_clear_managed_dict_ft_memory_error(self):
416419 def worker ():
417420 # This needs to be in a separate thread for the crash to happen:
418421 with support .catch_unraisable_exception () as ex :
419- # `clear ` used to crash:
420- _testcapi .call_with_nomemory (0 , 1 , clear , obj )
422+ # `clear_managed_dict ` used to crash:
423+ _testcapi .call_with_nomemory (0 , 1 , clear_managed_dict , obj )
421424 self .assertIsNotNone (ex .unraisable )
422425 self .assertIs (ex .unraisable .exc_type , MemoryError )
423426 self .assertIn ('managed dict' , ex .unraisable .err_msg )
0 commit comments