From ebd571bb18d2cf00ebc70db8090217fc62d00e98 Mon Sep 17 00:00:00 2001 From: Tyler Smart Date: Sat, 19 Aug 2023 12:04:59 -0600 Subject: [PATCH] Move _from_module override to pre-existsing DocTestFinder subclass --- src/_pytest/doctest.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/_pytest/doctest.py b/src/_pytest/doctest.py index e8bf92d95..c99ccbbb1 100644 --- a/src/_pytest/doctest.py +++ b/src/_pytest/doctest.py @@ -537,14 +537,11 @@ class DoctestModule(Module): tests, obj, name, module, source_lines, globs, seen ) - class CachedPropertyAwareDocTestFinder(MockAwareDocTestFinder): def _from_module(self, module, object): - """Doctest code does not take into account `@cached_property`, - this is a hackish way to fix it. https://github.com/python/cpython/issues/107995 - - Wrap Doctest finder so that when it calls `_from_module` for - a cached_property it uses the underlying function instead of the - wrapped cached_property object. + """`cached_property` objects will are never considered a part + of the 'current module'. As such they are skipped by doctest. + Here we override `_from_module` to check the underlying + function instead. https://github.com/python/cpython/issues/107995 """ if isinstance(object, functools.cached_property): object = object.func @@ -571,7 +568,7 @@ class DoctestModule(Module): else: raise # Uses internal doctest module parsing mechanism. - finder = CachedPropertyAwareDocTestFinder() + finder = MockAwareDocTestFinder() optionflags = get_optionflags(self) runner = _get_runner( verbose=False,