diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-05-23 12:56:33 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-05-23 12:58:32 +0200 |
| commit | bf5249fc8e0dd6e0c4c3101fda500d6966b6dcfc (patch) | |
| tree | 2293c0cec5d8482d31216a2850fbeb8adec0ebc1 | |
| parent | c78a4421de0fc3240b91d59e8f9028331777c624 (diff) | |
[4.2.x] 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
https://github.com/python/cpython/commit/55c99d97e14618dfce41472dd4446f763b0da13f
Backport of fc9c90d9c4611d441d2617a7d74f622b1f520f7c from main
| -rw-r--r-- | tests/utils_tests/test_functional.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/tests/utils_tests/test_functional.py b/tests/utils_tests/test_functional.py index 1e403f351b..803978e604 100644 --- a/tests/utils_tests/test_functional.py +++ b/tests/utils_tests/test_functional.py @@ -4,6 +4,7 @@ from django.test import SimpleTestCase from django.test.utils import ignore_warnings from django.utils.deprecation import RemovedInDjango50Warning from django.utils.functional import cached_property, classproperty, lazy +from django.utils.version import PY312 class FunctionalTests(SimpleTestCase): @@ -156,7 +157,18 @@ class FunctionalTests(SimpleTestCase): def test_cached_property_reuse_different_names(self): """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: @cached_property @@ -165,15 +177,8 @@ class FunctionalTests(SimpleTestCase): b = a - self.assertEqual( - str(ctx.exception.__context__), - str( - TypeError( - "Cannot assign the same cached_property to two different " - "names ('a' and 'b')." - ) - ), - ) + if not PY312: + self.assertEqual(str(ctx.exception.__context__), str(TypeError(type_msg))) def test_cached_property_reuse_same_name(self): """ |
