MCPcopy
hub / github.com/huggingface/transformers / collect

Method collect

src/transformers/testing_utils.py:2972–3039  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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 !!!!!!!!!!!

Callers 15

flush_memoryFunction · 0.80
cleanupMethod · 0.80
startMethod · 0.80
stopMethod · 0.80
load_sharded_checkpointFunction · 0.80
cleanupFunction · 0.80
__del__Method · 0.80
stopMethod · 0.80
delete_modelMethod · 0.80
tearDownClassMethod · 0.80
tearDownMethod · 0.80
tearDownMethod · 0.80

Calls 2

HfDocTestParserClass · 0.85

Tested by

no test coverage detected