From 967144fd94d066179aa9cdb42710dba60685cd2b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 6 Jun 2024 11:13:32 -0400 Subject: [PATCH] Only rely on _find on Python 3.9 and earlier. --- src/_pytest/doctest.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/_pytest/doctest.py b/src/_pytest/doctest.py index 5dd220227..475df507a 100644 --- a/src/_pytest/doctest.py +++ b/src/_pytest/doctest.py @@ -505,12 +505,6 @@ class DoctestModule(Module): import doctest class MockAwareDocTestFinder(doctest.DocTestFinder): - """A hackish doctest finder that overrides stdlib internals to fix a stdlib bug. - - https://github.com/pytest-dev/pytest/issues/3456 - https://bugs.python.org/issue25532 - """ - if sys.version_info < (3, 11): def _find_lineno(self, obj, source_lines): @@ -533,16 +527,23 @@ class DoctestModule(Module): source_lines, ) - def _find( - self, tests, obj, name, module, source_lines, globs, seen - ) -> None: - if _is_mocked(obj): - return - with _patch_unwrap_mock_aware(): - # Type ignored because this is a private function. - super()._find( # type:ignore[misc] - tests, obj, name, module, source_lines, globs, seen - ) + if sys.version_info < (3, 10): + + def _find( + self, tests, obj, name, module, source_lines, globs, seen + ) -> None: + """Override _find to work around issue in stdlib. + + https://github.com/pytest-dev/pytest/issues/3456 + https://github.com/python/cpython/issues/69718 + """ + if _is_mocked(obj): + return + with _patch_unwrap_mock_aware(): + # Type ignored because this is a private function. + super()._find( # type:ignore[misc] + tests, obj, name, module, source_lines, globs, seen + ) if sys.version_info < (3, 13):