From af6e7e3de8c6167ec1848c72915469442eb8a965 Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Mon, 4 Dec 2023 15:54:08 +0000 Subject: [PATCH] Refs #34986 -- Fixed backends.postgresql.test_server_side_cursors.ServerSideCursorsPostgres tests for PyPy. --- tests/backends/postgresql/test_server_side_cursors.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/backends/postgresql/test_server_side_cursors.py b/tests/backends/postgresql/test_server_side_cursors.py index 5efc82da58..694421b5cb 100644 --- a/tests/backends/postgresql/test_server_side_cursors.py +++ b/tests/backends/postgresql/test_server_side_cursors.py @@ -5,6 +5,8 @@ from contextlib import contextmanager from django.db import connection, models from django.test import TestCase +from django.test.utils import garbage_collect +from django.utils.version import PYPY from ..models import Person @@ -88,14 +90,21 @@ class ServerSideCursorsPostgres(TestCase): persons = Person.objects.iterator() next(persons) # Open a server-side cursor del persons + garbage_collect() cursors = self.inspect_cursors() self.assertEqual(len(cursors), 0) + @unittest.skipIf( + PYPY, + reason="Cursor not closed properly due to differences in garbage collection.", + ) def test_server_side_cursors_setting(self): with self.override_db_setting(DISABLE_SERVER_SIDE_CURSORS=False): persons = Person.objects.iterator() self.assertUsesCursor(persons) del persons # Close server-side cursor + # On PyPy, the cursor is left open here and attempting to force garbage + # collection breaks the transaction wrapping the test. with self.override_db_setting(DISABLE_SERVER_SIDE_CURSORS=True): self.assertNotUsesCursor(Person.objects.iterator())