(self)
| 493 | |
| 494 | class DoctestModule(pytest.Module): |
| 495 | def collect(self) -> Iterable[DoctestItem]: |
| 496 | import doctest |
| 497 | |
| 498 | class MockAwareDocTestFinder(doctest.DocTestFinder): |
| 499 | """A hackish doctest finder that overrides stdlib internals to fix a stdlib bug. |
| 500 | |
| 501 | https://github.com/pytest-dev/pytest/issues/3456 |
| 502 | https://bugs.python.org/issue25532 |
| 503 | """ |
| 504 | |
| 505 | def _find_lineno(self, obj, source_lines): |
| 506 | """Doctest code does not take into account `@property`, this |
| 507 | is a hackish way to fix it. https://bugs.python.org/issue17446 |
| 508 | |
| 509 | Wrapped Doctests will need to be unwrapped so the correct |
| 510 | line number is returned. This will be reported upstream. #8796 |
| 511 | """ |
| 512 | if isinstance(obj, property): |
| 513 | obj = getattr(obj, "fget", obj) |
| 514 | |
| 515 | if hasattr(obj, "__wrapped__"): |
| 516 | # Get the main obj in case of it being wrapped |
| 517 | obj = inspect.unwrap(obj) |
| 518 | |
| 519 | # Type ignored because this is a private function. |
| 520 | return super()._find_lineno( # type:ignore[misc] |
| 521 | obj, |
| 522 | source_lines, |
| 523 | ) |
| 524 | |
| 525 | def _find( |
| 526 | self, tests, obj, name, module, source_lines, globs, seen |
| 527 | ) -> None: |
| 528 | if _is_mocked(obj): |
| 529 | return |
| 530 | with _patch_unwrap_mock_aware(): |
| 531 | |
| 532 | # Type ignored because this is a private function. |
| 533 | super()._find( # type:ignore[misc] |
| 534 | tests, obj, name, module, source_lines, globs, seen |
| 535 | ) |
| 536 | |
| 537 | if self.path.name == "conftest.py": |
| 538 | module = self.config.pluginmanager._importconftest( |
| 539 | self.path, |
| 540 | self.config.getoption("importmode"), |
| 541 | rootpath=self.config.rootpath, |
| 542 | ) |
| 543 | else: |
| 544 | try: |
| 545 | module = import_path(self.path, root=self.config.rootpath) |
| 546 | except ImportError: |
| 547 | if self.config.getvalue("doctest_ignore_import_errors"): |
| 548 | pytest.skip("unable to import module %r" % self.path) |
| 549 | else: |
| 550 | raise |
| 551 | # Uses internal doctest module parsing mechanism. |
| 552 | finder = MockAwareDocTestFinder() |
nothing calls this directly
no test coverage detected