Skip to content

Commit 28be4b8

Browse files
committed
Fix refcount test failing under pytest assertion rewriting
test_iterator_callback_no_leak fails on Python 3.11 in CI: pytest's assertion rewriting explodes the assert expression into frame temporaries, and one of them holds backend.cache[0] while sys.getrefcount runs, inflating the count from 2 to 3. On 3.14 the temporary does not survive, so the test passes there. Keep the getrefcount call out of the assert so no rewritten temporary can hold the object. Assisted-by: Kimi Code
1 parent 007c562 commit 28be4b8

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

test/test_refdb_backend.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ def test_iterator_callback_no_leak(testrepo: Repository) -> None:
209209
assert backend.cache is not None
210210
refcount = sys.getrefcount(backend.cache[0])
211211
list(testrepo.references.iterator())
212-
assert sys.getrefcount(backend.cache[0]) == refcount
212+
# Keep the getrefcount call out of the assert: pytest's assertion
213+
# rewriting holds the subscript result in a frame temporary, which
214+
# inflates the refcount on some Python versions (e.g. 3.11).
215+
new_refcount = sys.getrefcount(backend.cache[0])
216+
assert new_refcount == refcount
213217

214218

215219
def test_write(repo: Repository) -> None:

0 commit comments

Comments
 (0)