Instances must correctly increase/decrease the reference count of their types (#1029)
()
| 407 | |
| 408 | @pytest.mark.xfail("env.PYPY or env.GRAALPY") |
| 409 | def 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 | |
| 431 | def test_reentrant_implicit_conversion_failure(msg): |
nothing calls this directly
no test coverage detected