(self)
| 598 | |
| 599 | class IPDoctestModule(pytest.Module): |
| 600 | def collect(self) -> Iterable[IPDoctestItem]: |
| 601 | import doctest |
| 602 | from .ipdoctest import DocTestFinder, IPDocTestParser |
| 603 | |
| 604 | class MockAwareDocTestFinder(DocTestFinder): |
| 605 | """A hackish ipdoctest finder that overrides stdlib internals to fix a stdlib bug. |
| 606 | |
| 607 | https://github.com/pytest-dev/pytest/issues/3456 |
| 608 | https://bugs.python.org/issue25532 |
| 609 | """ |
| 610 | |
| 611 | def _find_lineno(self, obj, source_lines): |
| 612 | """Doctest code does not take into account `@property`, this |
| 613 | is a hackish way to fix it. https://bugs.python.org/issue17446 |
| 614 | |
| 615 | Wrapped Doctests will need to be unwrapped so the correct |
| 616 | line number is returned. This will be reported upstream. #8796 |
| 617 | """ |
| 618 | if isinstance(obj, property): |
| 619 | obj = getattr(obj, "fget", obj) |
| 620 | |
| 621 | if hasattr(obj, "__wrapped__"): |
| 622 | # Get the main obj in case of it being wrapped |
| 623 | obj = inspect.unwrap(obj) |
| 624 | |
| 625 | # Type ignored because this is a private function. |
| 626 | return super()._find_lineno( # type:ignore[misc] |
| 627 | obj, |
| 628 | source_lines, |
| 629 | ) |
| 630 | |
| 631 | def _find( |
| 632 | self, tests, obj, name, module, source_lines, globs, seen |
| 633 | ) -> None: |
| 634 | if _is_mocked(obj): |
| 635 | return |
| 636 | with _patch_unwrap_mock_aware(): |
| 637 | # Type ignored because this is a private function. |
| 638 | super()._find( # type:ignore[misc] |
| 639 | tests, obj, name, module, source_lines, globs, seen |
| 640 | ) |
| 641 | |
| 642 | if self.path.name == "conftest.py": |
| 643 | if pytest_version[0] < 7: |
| 644 | module = self.config.pluginmanager._importconftest( |
| 645 | self.path, |
| 646 | self.config.getoption("importmode"), |
| 647 | ) |
| 648 | else: |
| 649 | kwargs = {"rootpath": self.config.rootpath} |
| 650 | if pytest_version >= (8, 1): |
| 651 | kwargs["consider_namespace_packages"] = False |
| 652 | module = self.config.pluginmanager._importconftest( |
| 653 | self.path, |
| 654 | self.config.getoption("importmode"), |
| 655 | **kwargs, |
| 656 | ) |
| 657 | else: |
no test coverage detected