mirror of
https://github.com/django/django.git
synced 2025-03-13 10:50:55 +00:00
Refs #34118 -- Fixed FunctionalTests.test_cached_property_reuse_different_names() on Python 3.12+.
Python 3.12+ no longer wraps exceptions in __set_name__, see
55c99d97e1
This commit is contained in:
parent
23abec9192
commit
fc9c90d9c4
@ -2,6 +2,7 @@ from unittest import mock
|
|||||||
|
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.utils.functional import cached_property, classproperty, lazy
|
from django.utils.functional import cached_property, classproperty, lazy
|
||||||
|
from django.utils.version import PY312
|
||||||
|
|
||||||
|
|
||||||
class FunctionalTests(SimpleTestCase):
|
class FunctionalTests(SimpleTestCase):
|
||||||
@ -130,7 +131,18 @@ class FunctionalTests(SimpleTestCase):
|
|||||||
|
|
||||||
def test_cached_property_reuse_different_names(self):
|
def test_cached_property_reuse_different_names(self):
|
||||||
"""Disallow this case because the decorated function wouldn't be cached."""
|
"""Disallow this case because the decorated function wouldn't be cached."""
|
||||||
with self.assertRaises(RuntimeError) as ctx:
|
type_msg = (
|
||||||
|
"Cannot assign the same cached_property to two different names ('a' and "
|
||||||
|
"'b')."
|
||||||
|
)
|
||||||
|
if PY312:
|
||||||
|
error_type = TypeError
|
||||||
|
msg = type_msg
|
||||||
|
else:
|
||||||
|
error_type = RuntimeError
|
||||||
|
msg = "Error calling __set_name__"
|
||||||
|
|
||||||
|
with self.assertRaisesMessage(error_type, msg) as ctx:
|
||||||
|
|
||||||
class ReusedCachedProperty:
|
class ReusedCachedProperty:
|
||||||
@cached_property
|
@cached_property
|
||||||
@ -139,15 +151,8 @@ class FunctionalTests(SimpleTestCase):
|
|||||||
|
|
||||||
b = a
|
b = a
|
||||||
|
|
||||||
self.assertEqual(
|
if not PY312:
|
||||||
str(ctx.exception.__context__),
|
self.assertEqual(str(ctx.exception.__context__), str(TypeError(type_msg)))
|
||||||
str(
|
|
||||||
TypeError(
|
|
||||||
"Cannot assign the same cached_property to two different "
|
|
||||||
"names ('a' and 'b')."
|
|
||||||
)
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_cached_property_reuse_same_name(self):
|
def test_cached_property_reuse_same_name(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user