@@ -505,43 +505,46 @@ def collect(self) -> Iterable[DoctestItem]:
505
505
import doctest
506
506
507
507
class MockAwareDocTestFinder (doctest .DocTestFinder ):
508
- """A hackish doctest finder that overrides stdlib internals to fix a stdlib bug.
509
-
510
- https://github.com/pytest-dev/pytest/issues/3456
511
- https://bugs.python.org/issue25532
512
- """
513
-
514
- def _find_lineno (self , obj , source_lines ):
515
- """Doctest code does not take into account `@property`, this
516
- is a hackish way to fix it. https://bugs.python.org/issue17446
517
-
518
- Wrapped Doctests will need to be unwrapped so the correct
519
- line number is returned. This will be reported upstream. #8796
520
- """
521
- if isinstance (obj , property ):
522
- obj = getattr (obj , "fget" , obj )
523
-
524
- if hasattr (obj , "__wrapped__" ):
525
- # Get the main obj in case of it being wrapped
526
- obj = inspect .unwrap (obj )
527
-
528
- # Type ignored because this is a private function.
529
- return super ()._find_lineno ( # type:ignore[misc]
530
- obj ,
531
- source_lines ,
532
- )
508
+ if sys .version_info < (3 , 11 ):
509
+
510
+ def _find_lineno (self , obj , source_lines ):
511
+ """On older Pythons, doctest code does not take into account
512
+ `@property`. https://github.com/python/cpython/issues/61648
513
+
514
+ Moreover, wrapped Doctests need to be unwrapped so the correct
515
+ line number is returned. #8796
516
+ """
517
+ if isinstance (obj , property ):
518
+ obj = getattr (obj , "fget" , obj )
519
+
520
+ if hasattr (obj , "__wrapped__" ):
521
+ # Get the main obj in case of it being wrapped
522
+ obj = inspect .unwrap (obj )
533
523
534
- def _find (
535
- self , tests , obj , name , module , source_lines , globs , seen
536
- ) -> None :
537
- if _is_mocked (obj ):
538
- return
539
- with _patch_unwrap_mock_aware ():
540
524
# Type ignored because this is a private function.
541
- super ()._find ( # type:ignore[misc]
542
- tests , obj , name , module , source_lines , globs , seen
525
+ return super ()._find_lineno ( # type:ignore[misc]
526
+ obj ,
527
+ source_lines ,
543
528
)
544
529
530
+ if sys .version_info < (3 , 10 ):
531
+
532
+ def _find (
533
+ self , tests , obj , name , module , source_lines , globs , seen
534
+ ) -> None :
535
+ """Override _find to work around issue in stdlib.
536
+
537
+ https://github.com/pytest-dev/pytest/issues/3456
538
+ https://github.com/python/cpython/issues/69718
539
+ """
540
+ if _is_mocked (obj ):
541
+ return # pragma: no cover
542
+ with _patch_unwrap_mock_aware ():
543
+ # Type ignored because this is a private function.
544
+ super ()._find ( # type:ignore[misc]
545
+ tests , obj , name , module , source_lines , globs , seen
546
+ )
547
+
545
548
if sys .version_info < (3 , 13 ):
546
549
547
550
def _from_module (self , module , object ):
@@ -556,9 +559,6 @@ def _from_module(self, module, object):
556
559
# Type ignored because this is a private function.
557
560
return super ()._from_module (module , object ) # type: ignore[misc]
558
561
559
- else : # pragma: no cover
560
- pass
561
-
562
562
try :
563
563
module = self .obj
564
564
except Collector .CollectError :
0 commit comments