diff --git a/django/test/testcases.py b/django/test/testcases.py index 41d01b89b4..7d12594177 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -1139,23 +1139,7 @@ class TestData: if instance is None: return self.data memo = self.get_memo(instance) - try: - data = deepcopy(self.data, memo) - except TypeError: - # RemovedInDjango41Warning. - msg = ( - "Assigning objects which don't support copy.deepcopy() during " - "setUpTestData() is deprecated. Either assign the %s " - "attribute during setUpClass() or setUp(), or add support for " - "deepcopy() to %s.%s.%s." - ) % ( - self.name, - owner.__module__, - owner.__qualname__, - self.name, - ) - warnings.warn(msg, category=RemovedInDjango41Warning, stacklevel=2) - data = self.data + data = deepcopy(self.data, memo) setattr(instance, self.name, data) return data diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt index 8a65b94581..bf3f3a848f 100644 --- a/docs/releases/4.1.txt +++ b/docs/releases/4.1.txt @@ -246,4 +246,6 @@ in Django 4.1. See :ref:`deprecated-features-3.2` for details on these changes, including how to remove usage of these features. -* ... +* Support for assigning objects which don't support creating deep copies with + ``copy.deepcopy()`` to class attributes in ``TestCase.setUpTestData()`` is + removed. diff --git a/tests/test_utils/test_testcase.py b/tests/test_utils/test_testcase.py index 9b11168b13..1261006092 100644 --- a/tests/test_utils/test_testcase.py +++ b/tests/test_utils/test_testcase.py @@ -1,9 +1,8 @@ from functools import wraps from django.db import IntegrityError, connections, transaction -from django.test import TestCase, ignore_warnings, skipUnlessDBFeature +from django.test import TestCase, skipUnlessDBFeature from django.test.testcases import TestData -from django.utils.deprecation import RemovedInDjango41Warning from .models import Car, Person, PossessedCar @@ -54,11 +53,6 @@ class TestTestCase(TestCase): self.reset_sequences = old_reset_sequences -class NonDeepCopyAble: - def __deepcopy__(self, memo): - raise TypeError - - def assert_no_queries(test): @wraps(test) def inner(self): @@ -79,7 +73,6 @@ class TestDataTests(TestCase): car=cls.car, belongs_to=cls.jim_douglas, ) - cls.non_deepcopy_able = NonDeepCopyAble() @assert_no_queries def test_class_attribute_equality(self): @@ -104,21 +97,6 @@ class TestDataTests(TestCase): self.assertIs(self.herbie.car, self.car) self.assertIs(self.herbie.belongs_to, self.jim_douglas) - @ignore_warnings(category=RemovedInDjango41Warning) - def test_undeepcopyable(self): - self.assertIs(self.non_deepcopy_able, self.__class__.non_deepcopy_able) - - def test_undeepcopyable_warning(self): - msg = ( - "Assigning objects which don't support copy.deepcopy() during " - "setUpTestData() is deprecated. Either assign the " - "non_deepcopy_able attribute during setUpClass() or setUp(), or " - "add support for deepcopy() to " - "test_utils.test_testcase.TestDataTests.non_deepcopy_able." - ) - with self.assertRaisesMessage(RemovedInDjango41Warning, msg): - self.non_deepcopy_able - def test_repr(self): self.assertEqual( repr(TestData('attr', 'value')),