From 189fcb7ac6897f47a3ca60d81a755bfac34505a0 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 7 Sep 2023 10:06:11 -0300 Subject: [PATCH] Account for Python 3.7 in the 7.4.x branch --- src/_pytest/doctest.py | 4 +++- testing/test_doctest.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/_pytest/doctest.py b/src/_pytest/doctest.py index 73ee483b3..ca41a98ea 100644 --- a/src/_pytest/doctest.py +++ b/src/_pytest/doctest.py @@ -545,7 +545,9 @@ class DoctestModule(Module): Here we override `_from_module` to check the underlying function instead. https://github.com/python/cpython/issues/107995 """ - if isinstance(object, functools.cached_property): + if hasattr(functools, "cached_property") and isinstance( + object, functools.cached_property + ): object = object.func # Type ignored because this is a private function. diff --git a/testing/test_doctest.py b/testing/test_doctest.py index 2cf5b019c..665bdb73b 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -482,6 +482,9 @@ class TestDoctests: reprec = pytester.inline_run(p, "--doctest-modules") reprec.assertoutcome(failed=1) + @pytest.mark.skipif( + sys.version_info[:2] <= (3, 7), reason="Only Python 3.7 or less" + ) def test_doctest_cached_property(self, pytester: Pytester): p = pytester.makepyfile( """