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

Method checked_call

src/_pytest/_py/error.py:81–111  ·  view source on GitHub ↗

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 """Call a function and raise an errno-exception if applicable."""
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, "errno"):
92 raise
93 if sys.platform == "win32":
94 try:
95 # error: Invalid index type "Optional[int]" for "dict[int, int]"; expected type "int" [index]
96 # OK to ignore because we catch the KeyError below.
97 cls = self._geterrnoclass(_winerrnomap[value.errno]) # type:ignore[index]
98 except KeyError:
99 raise value
100 else:
101 # we are not on Windows, or we got a proper OSError
102 if value.errno is None:
103 cls = type(
104 "UnknownErrnoNone",
105 (Error,),
106 {"__module__": "py.error", "__doc__": None},
107 )
108 else:
109 cls = self._geterrnoclass(value.errno)
110
111 raise cls(f"{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