mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
Refs #32114 -- Fixed test crash on non-picklable objects in subtests when PickleError is raised.
Related to the https://github.com/python/cpython/issues/73373. Follow up to c09e8f5fd8f977bf16e9ec5d11b370151fc81ea8.
This commit is contained in:
parent
18d79033b9
commit
ef2434f850
@ -100,7 +100,7 @@ def is_pickable(obj):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
pickle.loads(pickle.dumps(obj))
|
pickle.loads(pickle.dumps(obj))
|
||||||
except (AttributeError, TypeError):
|
except (AttributeError, TypeError, pickle.PickleError):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -3,17 +3,31 @@ from functools import wraps
|
|||||||
|
|
||||||
from django.db import IntegrityError, connections, transaction
|
from django.db import IntegrityError, connections, transaction
|
||||||
from django.test import TestCase, skipUnlessDBFeature
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
from django.test.testcases import DatabaseOperationForbidden, SimpleTestCase, TestData
|
from django.test.testcases import (
|
||||||
|
DatabaseOperationForbidden,
|
||||||
|
SimpleTestCase,
|
||||||
|
TestData,
|
||||||
|
is_pickable,
|
||||||
|
)
|
||||||
|
|
||||||
from .models import Car, Person, PossessedCar
|
from .models import Car, Person, PossessedCar
|
||||||
|
|
||||||
|
|
||||||
|
class UnpicklableObject:
|
||||||
|
def __getstate__(self):
|
||||||
|
raise pickle.PickleError("cannot be pickled for testing reasons")
|
||||||
|
|
||||||
|
|
||||||
class TestSimpleTestCase(SimpleTestCase):
|
class TestSimpleTestCase(SimpleTestCase):
|
||||||
def test_is_picklable_with_non_picklable_properties(self):
|
def test_is_picklable_with_non_picklable_properties(self):
|
||||||
"""ParallelTestSuite requires that all TestCases are picklable."""
|
"""ParallelTestSuite requires that all TestCases are picklable."""
|
||||||
self.non_picklable = lambda: 0
|
self.non_picklable = lambda: 0
|
||||||
self.assertEqual(self, pickle.loads(pickle.dumps(self)))
|
self.assertEqual(self, pickle.loads(pickle.dumps(self)))
|
||||||
|
|
||||||
|
def test_is_picklable_with_non_picklable_object(self):
|
||||||
|
unpicklable_obj = UnpicklableObject()
|
||||||
|
self.assertEqual(is_pickable(unpicklable_obj), False)
|
||||||
|
|
||||||
|
|
||||||
class TestTestCase(TestCase):
|
class TestTestCase(TestCase):
|
||||||
@skipUnlessDBFeature("can_defer_constraint_checks")
|
@skipUnlessDBFeature("can_defer_constraint_checks")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user