From 1a17d6d48c1b8e0d3f04ed88bf58867b8e240e4a Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Wed, 17 Mar 2021 02:14:07 +0100 Subject: [PATCH] Debug use count --- tests/test_class_sh_basic.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_class_sh_basic.py b/tests/test_class_sh_basic.py index 3727dcdb59..48551b1f23 100644 --- a/tests/test_class_sh_basic.py +++ b/tests/test_class_sh_basic.py @@ -3,6 +3,7 @@ import re import pytest +import sys from pybind11_tests import class_sh_basic as m @@ -144,11 +145,14 @@ def test_unique_ptr_cref_roundtrip(num_round_trips=1000): ) def test_unique_ptr_consumer_roundtrip(pass_f, rtrn_f, moved_out, moved_in): c = m.uconsumer() - assert not c.valid() recycled = m.atyp("passenger") mtxt_orig = m.get_mtxt(recycled) + ptr_orig = m.get_ptr(recycled) assert re.match("passenger_(MvCtor){1,2}", mtxt_orig) + __copy = recycled # noqa: F841 + assert sys.getrefcount(recycled) == 3 + pass_f(c, recycled) if moved_out: with pytest.raises(ValueError) as excinfo: @@ -156,8 +160,9 @@ def test_unique_ptr_consumer_roundtrip(pass_f, rtrn_f, moved_out, moved_in): assert "Python instance was disowned" in str(excinfo.value) recycled = rtrn_f(c) - assert c.valid() != moved_in - assert m.get_mtxt(recycled) == mtxt_orig + assert c.valid() != moved_in # consumer gave up ownership? + assert m.get_ptr(recycled) == ptr_orig # underlying C++ object never changes + assert m.get_mtxt(recycled) == mtxt_orig # object was not moved or copied def test_py_type_handle_of_atyp():