MCPcopy
hub / github.com/pytest-dev/pytest / checked_call

Method checked_call

src/_pytest/_py/error.py:81–111  ·  src/_pytest/_py/error.py::ErrorMaker.checked_call

Call a function and raise an errno-exception if applicable.

(
        self, func: Callable[P, R], *args: P.args, **kwargs: P.kwargs
    )

Source from the content-addressed store, hash-verified

79 return errorcls
80
81 def checked_call(
82 self, func: Callable[P, R], *args: P.args, **kwargs: P.kwargs
83 ) -> R:
84 class="st">""class="st">"Call a function and raise an errno-exception if applicable."class="st">""
85 __tracebackhide__ = True
86 try:
87 return func(*args, **kwargs)
88 except Error:
89 raise
90 except OSError as value:
91 if not hasattr(value, class="st">"errno"):
92 raise
93 if sys.platform == class="st">"win32":
94 try:
95 class="cm"># error: Invalid index type class="st">"Optional[int]" for class="st">"dict[int, int]"; expected type class="st">"int" [index]
96 class="cm"># OK to ignore because we catch the KeyError below.
97 cls = self._geterrnoclass(_winerrnomap[value.errno]) class="cm"># type:ignore[index]
98 except KeyError:
99 raise value
100 else:
101 class="cm"># we are not on Windows, or we got a proper OSError
102 if value.errno is None:
103 cls = type(
104 class="st">"UnknownErrnoNone",
105 (Error,),
106 {class="st">"__module__": class="st">"py.error", class="st">"__doc__": None},
107 )
108 else:
109 cls = self._geterrnoclass(value.errno)
110
111 raise cls(fclass="st">"{func.__name__}{args!r}")
112
113
114_error_maker = ErrorMaker()

Callers 15

ownerMethod · 0.80
groupMethod · 0.80
__init__Method · 0.80
chownMethod · 0.80
readlinkMethod · 0.80
mklinktoMethod · 0.80
mksymlinktoMethod · 0.80
loadMethod · 0.80
samefileMethod · 0.80
removeMethod · 0.80
openMethod · 0.80
listdirMethod · 0.80

Calls 3

_geterrnoclassMethod · 0.95
clsFunction · 0.85
funcFunction · 0.50

Tested by

no test coverage detected