Skip to content

Commit

Permalink
Refs #31395 -- Removed support for assigning objects which don't supp…
Browse files Browse the repository at this point in the history
…ort deepcopy() in setUpTestData().

Per deprecation timeline.
  • Loading branch information
felixxm committed Sep 20, 2021
1 parent 97237ad commit 2e10abe
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 41 deletions.
18 changes: 1 addition & 17 deletions django/test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,23 +1139,7 @@ def __get__(self, instance, owner):
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

Expand Down
4 changes: 3 additions & 1 deletion docs/releases/4.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
24 changes: 1 addition & 23 deletions tests/test_utils/test_testcase.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -54,11 +53,6 @@ def test_reset_sequences(self):
self.reset_sequences = old_reset_sequences


class NonDeepCopyAble:
def __deepcopy__(self, memo):
raise TypeError


def assert_no_queries(test):
@wraps(test)
def inner(self):
Expand All @@ -79,7 +73,6 @@ def setUpTestData(cls):
car=cls.car,
belongs_to=cls.jim_douglas,
)
cls.non_deepcopy_able = NonDeepCopyAble()

@assert_no_queries
def test_class_attribute_equality(self):
Expand All @@ -104,21 +97,6 @@ def test_known_related_objects_identity_preservation(self):
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')),
Expand Down

0 comments on commit 2e10abe

Please sign in to comment.