From 731afde9e334ccdbd187d307e4173613e154024b Mon Sep 17 00:00:00 2001 From: Jameel Al-Aziz Date: Tue, 7 Sep 2021 02:02:10 -0700 Subject: [PATCH] Fix tests --- tests/test_fields.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test_fields.py b/tests/test_fields.py index aff0a3f2..a50ffb81 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -19,6 +19,14 @@ from drf_spectacular.generators import SchemaGenerator from tests import assert_schema +try: + functools_cached_property = functools.cached_property # type: ignore +except ImportError: + # functools.cached_property is only available in Python 3.8+. + # We re-use Django's cached_property when it's not avaiable to + # keep tests unified across Python versions. + functools_cached_property = cached_property + fs = FileSystemStorage(location=tempfile.gettempdir()) @@ -113,7 +121,7 @@ def field_model_property_float(self) -> float: def field_model_cached_property_float(self) -> float: return 1.337 - @functools.cached_property # type: ignore + @functools_cached_property def field_model_py_cached_property_float(self) -> float: return 1.337 @@ -139,7 +147,7 @@ def sub_object(self) -> SubObject: def sub_object_cached(self) -> SubObject: return SubObject(self) - @functools.cached_property # type: ignore + @functools_cached_property def sub_object_py_cached(self) -> SubObject: return SubObject(self)