summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2021-09-16 09:12:56 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-09-20 21:23:01 +0200
commite2be307b3ab6ebf339b3a765fe64967c9602266f (patch)
treee6a7a2c3d5c463c9ced7e094781f4066b5a19dba
parent75d6c4ae6df93c4c4d8621aced3a180afa18a6cb (diff)
Refs #31235 -- Made assertQuerysetEqual() not call repr() on a queryset when compared to string values.
Per deprecation timeline.
-rw-r--r--django/test/testcases.py19
-rw-r--r--docs/releases/4.1.txt3
-rw-r--r--docs/topics/testing/tools.txt7
-rw-r--r--tests/test_utils/tests.py31
4 files changed, 5 insertions, 55 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 7d12594177..ebc8b541ac 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -6,7 +6,6 @@ import posixpath
import sys
import threading
import unittest
-import warnings
from collections import Counter
from contextlib import contextmanager
from copy import copy, deepcopy
@@ -42,7 +41,6 @@ from django.test.utils import (
CaptureQueriesContext, ContextList, compare_xml, modify_settings,
override_settings,
)
-from django.utils.deprecation import RemovedInDjango41Warning
from django.utils.functional import classproperty
from django.utils.version import PY310
from django.views.static import serve
@@ -1059,23 +1057,6 @@ class TransactionTestCase(SimpleTestCase):
def assertQuerysetEqual(self, qs, values, transform=None, ordered=True, msg=None):
values = list(values)
- # RemovedInDjango41Warning.
- if transform is None:
- if (
- values and isinstance(values[0], str) and
- qs and not isinstance(qs[0], str)
- ):
- # Transform qs using repr() if the first element of values is a
- # string and the first element of qs is not (which would be the
- # case if qs is a flattened values_list).
- warnings.warn(
- "In Django 4.1, repr() will not be called automatically "
- "on a queryset when compared to string values. Set an "
- "explicit 'transform' to silence this warning.",
- category=RemovedInDjango41Warning,
- stacklevel=2,
- )
- transform = repr
items = qs
if transform is not None:
items = map(transform, items)
diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt
index 8fbcbf145b..8cb4297d0e 100644
--- a/docs/releases/4.1.txt
+++ b/docs/releases/4.1.txt
@@ -257,3 +257,6 @@ to remove usage of these features.
``django.core.validators.EmailValidator`` are removed.
* The ``default_app_config`` application configuration variable is removed.
+
+* ``TransactionTestCase.assertQuerysetEqual()`` no longer calls ``repr()`` on a
+ queryset when compared to string values.
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
index a99ee77cb0..99aff9c116 100644
--- a/docs/topics/testing/tools.txt
+++ b/docs/topics/testing/tools.txt
@@ -1700,13 +1700,6 @@ your test suite.
Output in case of error can be customized with the ``msg`` argument.
- .. deprecated:: 3.2
-
- If ``transform`` is not provided and ``values`` is a list of strings,
- it's compared to a list produced by applying ``repr()`` to each member
- of ``qs``. This behavior is deprecated and will be removed in Django
- 4.1. If you need it, explicitly set ``transform`` to ``repr``.
-
.. method:: TransactionTestCase.assertNumQueries(num, func, *args, **kwargs)
Asserts that when ``func`` is called with ``*args`` and ``**kwargs`` that
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index 82ec36ab38..ce328cd90a 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -17,8 +17,8 @@ from django.forms import EmailField, IntegerField
from django.http import HttpResponse
from django.template.loader import render_to_string
from django.test import (
- SimpleTestCase, TestCase, TransactionTestCase, ignore_warnings,
- skipIfDBFeature, skipUnlessDBFeature,
+ SimpleTestCase, TestCase, TransactionTestCase, skipIfDBFeature,
+ skipUnlessDBFeature,
)
from django.test.html import HTMLParseError, parse_html
from django.test.utils import (
@@ -26,7 +26,6 @@ from django.test.utils import (
override_settings, setup_test_environment,
)
from django.urls import NoReverseMatch, path, reverse, reverse_lazy
-from django.utils.deprecation import RemovedInDjango41Warning
from django.utils.log import DEFAULT_LOGGING
from .models import Car, Person, PossessedCar
@@ -362,32 +361,6 @@ class AssertQuerysetEqualTests(TestCase):
self.assertIn(name, exception_msg)
-class AssertQuerysetEqualDeprecationTests(TestCase):
- @classmethod
- def setUpTestData(cls):
- cls.p1 = Person.objects.create(name='p1')
- cls.p2 = Person.objects.create(name='p2')
-
- @ignore_warnings(category=RemovedInDjango41Warning)
- def test_str_values(self):
- self.assertQuerysetEqual(
- Person.objects.all().order_by('name'),
- [repr(self.p1), repr(self.p2)],
- )
-
- def test_str_values_warning(self):
- msg = (
- "In Django 4.1, repr() will not be called automatically on a "
- "queryset when compared to string values. Set an explicit "
- "'transform' to silence this warning."
- )
- with self.assertRaisesMessage(RemovedInDjango41Warning, msg):
- self.assertQuerysetEqual(
- Person.objects.all().order_by('name'),
- [repr(self.p1), repr(self.p2)],
- )
-
-
@override_settings(ROOT_URLCONF='test_utils.urls')
class CaptureQueriesContextManagerTests(TestCase):