(self)
| 499 | |
| 500 | class DoctestModule(Module): |
| 501 | def collect(self) -> Iterable[DoctestItem]: |
| 502 | import doctest |
| 503 | |
| 504 | class MockAwareDocTestFinder(doctest.DocTestFinder): |
| 505 | py_ver_info_minor = sys.version_info[:2] |
| 506 | is_find_lineno_broken = ( |
| 507 | py_ver_info_minor < (3, 11) |
| 508 | or (py_ver_info_minor == (3, 11) and sys.version_info.micro < 9) |
| 509 | or (py_ver_info_minor == (3, 12) and sys.version_info.micro < 3) |
| 510 | ) |
| 511 | if is_find_lineno_broken: |
| 512 | |
| 513 | def _find_lineno(self, obj, source_lines): |
| 514 | """On older Pythons, doctest code does not take into account |
| 515 | `@property`. https://github.com/python/cpython/issues/61648 |
| 516 | |
| 517 | Moreover, wrapped Doctests need to be unwrapped so the correct |
| 518 | line number is returned. #8796 |
| 519 | """ |
| 520 | if isinstance(obj, property): |
| 521 | obj = getattr(obj, "fget", obj) |
| 522 | |
| 523 | if hasattr(obj, "__wrapped__"): |
| 524 | # Get the main obj in case of it being wrapped |
| 525 | obj = inspect.unwrap(obj) |
| 526 | |
| 527 | # Type ignored because this is a private function. |
| 528 | return super()._find_lineno( # type:ignore[misc] |
| 529 | obj, |
| 530 | source_lines, |
| 531 | ) |
| 532 | |
| 533 | if sys.version_info < (3, 13): |
| 534 | |
| 535 | def _from_module(self, module, object): |
| 536 | """`cached_property` objects are never considered a part |
| 537 | of the 'current module'. As such they are skipped by doctest. |
| 538 | Here we override `_from_module` to check the underlying |
| 539 | function instead. https://github.com/python/cpython/issues/107995 |
| 540 | """ |
| 541 | if isinstance(object, functools.cached_property): |
| 542 | object = object.func |
| 543 | |
| 544 | # Type ignored because this is a private function. |
| 545 | return super()._from_module(module, object) # type: ignore[misc] |
| 546 | |
| 547 | try: |
| 548 | module = self.obj |
| 549 | except Collector.CollectError: |
| 550 | if self.config.getvalue("doctest_ignore_import_errors"): |
| 551 | skip(f"unable to import module {self.path!r}") |
| 552 | else: |
| 553 | raise |
| 554 | |
| 555 | # doctests supports fixtures via `getfixture` and autouse. |
| 556 | self.session._fixturemanager.parsefactories(self) |
| 557 | |
| 558 | # Uses internal doctest module parsing mechanism. |
nothing calls this directly
no test coverage detected