aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/tests/samplebinding/class_fields_test.py
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2025-07-28 09:52:10 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2025-10-15 11:59:13 +0200
commit08bc8b8d6b6020e5fd307fd1a4a14baf908db6cb (patch)
treeeebe966df40630061840f339d055846491f5aee9 /sources/shiboken6/tests/samplebinding/class_fields_test.py
parent3369a18ff24046e21b6e505ab5399f2d69101a8d (diff)
Fix reference count tests (2) to pass in Python 3.14 (obscure cases)
As of 3.14, the interpreter will sometimes just borrow references and newly created objects may have different initial reference counts. Pick-to: 6.10 6.8 Task-number: PYSIDE-3147 Change-Id: I845460202abb95715ebf395b378b81b7790660bb Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/tests/samplebinding/class_fields_test.py')
-rw-r--r--sources/shiboken6/tests/samplebinding/class_fields_test.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/sources/shiboken6/tests/samplebinding/class_fields_test.py b/sources/shiboken6/tests/samplebinding/class_fields_test.py
index 63b8b8fa3..11052c5ba 100644
--- a/sources/shiboken6/tests/samplebinding/class_fields_test.py
+++ b/sources/shiboken6/tests/samplebinding/class_fields_test.py
@@ -17,6 +17,9 @@ init_paths()
from sample import Derived, Point, ObjectType
+REF_COUNT_DELTA = 2 if sys.version_info >= (3, 14) else 1
+
+
class TestAccessingCppFields(unittest.TestCase):
'''Simple test case for accessing the exposed C++ class fields.'''
@@ -125,7 +128,7 @@ class TestAccessingCppFields(unittest.TestCase):
refcount1 = sys.getrefcount(o1)
d.objectTypeField = o1
self.assertEqual(d.objectTypeField, o1)
- self.assertEqual(sys.getrefcount(d.objectTypeField), refcount1 + 1)
+ self.assertEqual(sys.getrefcount(d.objectTypeField), refcount1 + REF_COUNT_DELTA)
# attributing a new object to instance's field should decrease the previous
# object's reference count
@@ -134,7 +137,7 @@ class TestAccessingCppFields(unittest.TestCase):
d.objectTypeField = o2
self.assertEqual(d.objectTypeField, o2)
self.assertEqual(sys.getrefcount(o1), refcount1)
- self.assertEqual(sys.getrefcount(d.objectTypeField), refcount2 + 1)
+ self.assertEqual(sys.getrefcount(d.objectTypeField), refcount2 + REF_COUNT_DELTA)
@unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testRefCountingOfReferredObjectAfterDeletingReferrer(self):