From 9193b8e7143594723e6272e6501e550237199cdc Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Tue, 9 Jul 2024 13:27:31 -0700 Subject: [PATCH] Additional `assert is_disowned()` in test_class_sh_disowning.py (#5234) --- tests/test_class_sh_disowning.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/test_class_sh_disowning.py b/tests/test_class_sh_disowning.py index 63cdd4edb6..52568203e9 100644 --- a/tests/test_class_sh_disowning.py +++ b/tests/test_class_sh_disowning.py @@ -5,17 +5,26 @@ from pybind11_tests import class_sh_disowning as m +def is_disowned(obj): + try: + obj.get() + except ValueError: + return True + return False + + def test_same_twice(): while True: obj1a = m.Atype1(57) obj1b = m.Atype1(62) assert m.same_twice(obj1a, obj1b) == (57 * 10 + 1) * 100 + (62 * 10 + 1) * 10 + assert is_disowned(obj1a) + assert is_disowned(obj1b) obj1c = m.Atype1(0) with pytest.raises(ValueError): # Disowning works for one argument, but not both. m.same_twice(obj1c, obj1c) - with pytest.raises(ValueError): - obj1c.get() + assert is_disowned(obj1c) return # Comment out for manual leak checking (use `top` command). @@ -25,6 +34,8 @@ def test_mixed(): obj1a = m.Atype1(90) obj2a = m.Atype2(25) assert m.mixed(obj1a, obj2a) == (90 * 10 + 1) * 200 + (25 * 10 + 2) * 20 + assert is_disowned(obj1a) + assert is_disowned(obj2a) # The C++ order of evaluation of function arguments is (unfortunately) unspecified: # https://en.cppreference.com/w/cpp/language/eval_order @@ -40,13 +51,6 @@ def test_mixed(): # the already disowned obj1a fails as expected. m.mixed(obj1a, obj2b) - def is_disowned(obj): - try: - obj.get() - except ValueError: - return True - return False - # Either obj1b or obj2b was disowned in the expected failed m.mixed() calls above, but not # both. is_disowned_results = (is_disowned(obj1b), is_disowned(obj2b))