mirror of https://github.com/django/django.git
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 c09e8f5fd8
.
This commit is contained in:
parent
18d79033b9
commit
ef2434f850
|
@ -100,7 +100,7 @@ def is_pickable(obj):
|
|||
"""
|
||||
try:
|
||||
pickle.loads(pickle.dumps(obj))
|
||||
except (AttributeError, TypeError):
|
||||
except (AttributeError, TypeError, pickle.PickleError):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -3,17 +3,31 @@ from functools import wraps
|
|||
|
||||
from django.db import IntegrityError, connections, transaction
|
||||
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
|
||||
|
||||
|
||||
class UnpicklableObject:
|
||||
def __getstate__(self):
|
||||
raise pickle.PickleError("cannot be pickled for testing reasons")
|
||||
|
||||
|
||||
class TestSimpleTestCase(SimpleTestCase):
|
||||
def test_is_picklable_with_non_picklable_properties(self):
|
||||
"""ParallelTestSuite requires that all TestCases are picklable."""
|
||||
self.non_picklable = lambda: 0
|
||||
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):
|
||||
@skipUnlessDBFeature("can_defer_constraint_checks")
|
||||
|
|
Loading…
Reference in New Issue