summaryrefslogtreecommitdiff
path: root/tests/model_forms
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2023-11-21 15:11:58 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-11-28 06:19:38 +0100
commitbaf705f34a8c8977d042ce43c71f508f9ca4f8ce (patch)
tree6ee650aea8ba19532955839fcb0c39a0705af7e1 /tests/model_forms
parent051dbb53884eb202131c27dfdeac7c3ddd7b1072 (diff)
Refs #34986 -- Fixed some test assertions for PyPy.
These failures were due to minor inconsistencies or implementation differences between CPython and PyPy.
Diffstat (limited to 'tests/model_forms')
-rw-r--r--tests/model_forms/tests.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index 43bb770f7e..f706271106 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -25,6 +25,7 @@ from django.test import SimpleTestCase, TestCase, ignore_warnings, skipUnlessDBF
from django.test.utils import isolate_apps
from django.utils.choices import BlankChoiceIterator
from django.utils.deprecation import RemovedInDjango60Warning
+from django.utils.version import PYPY
from .models import (
Article,
@@ -3017,7 +3018,10 @@ class OtherModelFormTests(TestCase):
return ", ".join(c.name for c in obj.colours.all())
field = ColorModelChoiceField(ColourfulItem.objects.prefetch_related("colours"))
- with self.assertNumQueries(3): # would be 4 if prefetch is ignored
+ # CPython calls ModelChoiceField.__len__() when coercing to tuple. PyPy
+ # doesn't call __len__() and so .count() isn't called on the QuerySet.
+ # The following would trigger an extra query if prefetch were ignored.
+ with self.assertNumQueries(2 if PYPY else 3):
self.assertEqual(
tuple(field.choices),
(