Skip to content

Commit

Permalink
_from_module: Add caching from pytest upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Oct 14, 2023
1 parent dfbea51 commit 75b9322
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/doctest_docutils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import doctest
import functools
import linecache
import logging
import os
Expand Down Expand Up @@ -362,6 +363,27 @@ def condition(node: Node) -> bool:
if test is not None:
tests.append(test)

if sys.version_info < (3, 13):

def _from_module(
self, module: t.Optional[t.Union[str, types.ModuleType]], object: object
) -> bool:
"""`cached_property` objects 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

# Type ignored because this is a private function.
return t.cast(
bool, super()._from_module(module, object) # type:ignore[misc]
)

else: # pragma: no cover
pass

def _get_test(
self,
string: str,
Expand Down

0 comments on commit 75b9322

Please sign in to comment.