(self)
| 2970 | """ |
| 2971 | |
| 2972 | def collect(self) -> Iterable[DoctestItem]: |
| 2973 | class MockAwareDocTestFinder(doctest.DocTestFinder): |
| 2974 | """A hackish doctest finder that overrides stdlib internals to fix a stdlib bug. |
| 2975 | |
| 2976 | https://github.com/pytest-dev/pytest/issues/3456 https://bugs.python.org/issue25532 |
| 2977 | """ |
| 2978 | |
| 2979 | def _find_lineno(self, obj, source_lines): |
| 2980 | """Doctest code does not take into account `@property`, this |
| 2981 | is a hackish way to fix it. https://bugs.python.org/issue17446 |
| 2982 | |
| 2983 | Wrapped Doctests will need to be unwrapped so the correct line number is returned. This will be |
| 2984 | reported upstream. #8796 |
| 2985 | """ |
| 2986 | if isinstance(obj, property): |
| 2987 | obj = getattr(obj, "fget", obj) |
| 2988 | |
| 2989 | if hasattr(obj, "__wrapped__"): |
| 2990 | # Get the main obj in case of it being wrapped |
| 2991 | obj = inspect.unwrap(obj) |
| 2992 | |
| 2993 | # Type ignored because this is a private function. |
| 2994 | return super()._find_lineno( # type:ignore[misc] |
| 2995 | obj, |
| 2996 | source_lines, |
| 2997 | ) |
| 2998 | |
| 2999 | def _find(self, tests, obj, name, module, source_lines, globs, seen) -> None: |
| 3000 | if _is_mocked(obj): |
| 3001 | return |
| 3002 | with _patch_unwrap_mock_aware(): |
| 3003 | # Type ignored because this is a private function. |
| 3004 | super()._find( # type:ignore[misc] |
| 3005 | tests, obj, name, module, source_lines, globs, seen |
| 3006 | ) |
| 3007 | |
| 3008 | if self.path.name == "conftest.py": |
| 3009 | module = self.config.pluginmanager._importconftest( |
| 3010 | self.path, |
| 3011 | self.config.getoption("importmode"), |
| 3012 | rootpath=self.config.rootpath, |
| 3013 | ) |
| 3014 | else: |
| 3015 | try: |
| 3016 | module = import_path( |
| 3017 | self.path, |
| 3018 | root=self.config.rootpath, |
| 3019 | mode=self.config.getoption("importmode"), |
| 3020 | ) |
| 3021 | except ImportError: |
| 3022 | if self.config.getvalue("doctest_ignore_import_errors"): |
| 3023 | skip("unable to import module %r" % self.path) |
| 3024 | else: |
| 3025 | raise |
| 3026 | |
| 3027 | # !!!!!!!!!!! HF Specific !!!!!!!!!!! |
| 3028 | finder = MockAwareDocTestFinder(parser=HfDocTestParser()) |
| 3029 | # !!!!!!!!!!! HF Specific !!!!!!!!!!! |
no test coverage detected