Skip to content

Commit ebd571b

Browse files
committed
Move _from_module override to pre-existsing DocTestFinder subclass
1 parent d4fb6ac commit ebd571b

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/_pytest/doctest.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,11 @@ def _find(
537537
tests, obj, name, module, source_lines, globs, seen
538538
)
539539

540-
class CachedPropertyAwareDocTestFinder(MockAwareDocTestFinder):
541540
def _from_module(self, module, object):
542-
"""Doctest code does not take into account `@cached_property`,
543-
this is a hackish way to fix it. https://github.com/python/cpython/issues/107995
544-
545-
Wrap Doctest finder so that when it calls `_from_module` for
546-
a cached_property it uses the underlying function instead of the
547-
wrapped cached_property object.
541+
"""`cached_property` objects will are never considered a part
542+
of the 'current module'. As such they are skipped by doctest.
543+
Here we override `_from_module` to check the underlying
544+
function instead. https://github.com/python/cpython/issues/107995
548545
"""
549546
if isinstance(object, functools.cached_property):
550547
object = object.func
@@ -571,7 +568,7 @@ def _from_module(self, module, object):
571568
else:
572569
raise
573570
# Uses internal doctest module parsing mechanism.
574-
finder = CachedPropertyAwareDocTestFinder()
571+
finder = MockAwareDocTestFinder()
575572
optionflags = get_optionflags(self)
576573
runner = _get_runner(
577574
verbose=False,

0 commit comments

Comments
 (0)