MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_class_refcount

Function test_class_refcount

tests/test_class.py:409–428  ·  view source on GitHub ↗

Instances must correctly increase/decrease the reference count of their types (#1029)

()

Source from the content-addressed store, hash-verified

407
408@pytest.mark.xfail("env.PYPY or env.GRAALPY")
409def test_class_refcount():
410 """Instances must correctly increase/decrease the reference count of their types (#1029)"""
411
412 class PyDog(m.Dog):
413 pass
414
415 for cls in m.Dog, PyDog:
416 refcount_1 = refcount_immortal(cls)
417 molly = [cls("Molly") for _ in range(10)]
418 refcount_2 = refcount_immortal(cls)
419
420 del molly
421 pytest.gc_collect()
422 refcount_3 = refcount_immortal(cls)
423
424 # Python may report a large value here (above 30 bits), that's also fine
425 assert refcount_1 == refcount_3
426 assert (refcount_2 > refcount_1) or (
427 refcount_2 == refcount_1 and refcount_1 >= 2**29
428 )
429
430
431def test_reentrant_implicit_conversion_failure(msg):

Callers

nothing calls this directly

Calls 1

refcount_immortalFunction · 0.85

Tested by

no test coverage detected