MCPcopy Index your code
hub / github.com/ipython/ipython / collect

Method collect

IPython/testing/plugin/pytest_ipdoctest.py:600–682  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

598
599class 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:

Callers 6

flushMethod · 0.45
resetMethod · 0.45
innerFunction · 0.45
test_xdelMethod · 0.45

Calls 9

import_pathFunction · 0.85
IPDocTestParserClass · 0.85
get_optionflagsFunction · 0.85
_get_runnerFunction · 0.85
_get_checkerFunction · 0.85
_get_continue_on_failureFunction · 0.85
findMethod · 0.45
from_parentMethod · 0.45

Tested by

no test coverage detected