Skip to content

Commit a2bb5de

Browse files
committed
Fix for test failures with free-threaded Python
Look for changes in the number of allocated Vectors instead of whether there are any. For some reason, I'm getting Vectors already allocated when running pytest on the free-threaded version of Python. They are clearly referenced by something else that has run before these tests.
1 parent b5cbca7 commit a2bb5de

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tests/test_vm.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,10 +1086,17 @@ def tearDownClass(cls):
10861086
def setUp(self):
10871087
gc.collect()
10881088
gc.disable()
1089+
self._vector_count = 0
1090+
for obj in gc.get_objects(0):
1091+
if isinstance(obj, Vector):
1092+
self._vector_count += 1
10891093

10901094
def tearDown(self):
1095+
vector_count = 0
10911096
for obj in gc.get_objects(0):
1092-
self.assertNotIsInstance(obj, Vector, "Memory leak")
1097+
if isinstance(obj, Vector):
1098+
vector_count += 1
1099+
self.assertEqual(vector_count, self._vector_count, "Memory leak")
10931100
gc.enable()
10941101

10951102
def test_create(self):

0 commit comments

Comments
 (0)